Proposal: add vector arithmetic to array module

Paul Rubin phr-n2001 at nightsong.com
Mon Sep 24 05:01:04 EDT 2001


It seems almost unnatural that given two arrays of the same type
of element and the same length, I can't say "a = b + c" and get
the arrays added together element-wise.  There's various algorithms
I'd be able to speed up quite a bit that way.

Proposal: add some vector arithmetic operations to arrays.
  +,-,*,/   => pointwise addition, subtraction, etc.
  &, |, ^   => boolean and, or, xor

This should all be pretty simple and not really qualify as bloat.
And it's in the functional-programming spirit of some other parts of Python.

There could be a few other niceties added, like making 
  reduce(operator.add(array)) 
sum the array as part of the array package instead of first converting
the array to a list, if it doesn't already work that way.  That would
speed up computing inner products.  There could also be in-place
versions of the arithmetic operations: array.add(a,b,c) is like
"a = b + c", but would require that a,b,c all be the same length
and type, and would avoid deallocating and reallocating a.

Please suppress the urge to reply "use NumPy".  Numpy is a big package
that's not part of standard Python, with a lot of PDF documentation
and most importantly needs to be installed separately.  That makes it
a lot harder to distribute applications to non-technical users.  It's
bad enough that they already have to install Python to run Python apps.



More information about the Python-list mailing list