[Numpy-discussion] python reduce vs numpy reduce for outer product

Erik Tollerud erik.tollerud@gmail....
Sat Sep 26 18:17:05 CDT 2009


> I'm sure you mean np.multiply.reduce().
Yes, sorry - typo.

>> Or, if there's a better way to just start with the first 3 1d
>> vectorsand jump straight to the broadcast product (basically, an outer
>> product over arbitrary number of dimensions...)?
>
> Well, numpy doesn't support arbitrary numbers of dimensions, nor will
> your memory. You won't be able to do more than a handful of dimensions
> practically. Exactly what are you trying to do? Specifics, please, not
> toy examples.

Well, I'm not sure how to get too much more specific than what I just
described. I am computing moments of n-d input arrays given a
particular axis ... I want to take a sequence of 1D arrays, and get an
output has as many dimensions as the input sequence's length, with
each dimension's size matching the corresponding vector.
Symbolically, A[i,j,k,...] = v0[i]*v1[j]*v2[k]*...  A is then
multiplied by the input n-d array (same shape as A), and that is the
output.

And yes, practically, this will only work until I run out of memory,
but the reduce method works for the n=1,2, 3, and 4 cases, and
potentially in the future it will be needed for with higher (up to
maybe 8) dimensions that are small enough that they won't overwhelm
the memory. So it seems like a bad idea to write custom versions for
each potential dimensionality.


More information about the NumPy-Discussion mailing list