[Numpy-discussion] How operating arrays in a determined axis?
Warren Focke
focke at slac.stanford.edu
Mon Mar 19 15:40:54 CST 2001
On Mon, 19 Mar 2001, Aureli Soria Frisch wrote:
> Hello!
>
> I have a N-dimensional array A and I want to operate in one of the axis (k)
> with a 1 dimensional array (for instance, subtracting an array B of length
> k). I have looked for some solutions in the manual and did not found any.
>
> So after testing a lot I found following solution:
>
> A=Numeric.array(a)
>
> A.shape=(a1,a2,...,ak,...,aN) #where N is any int value
>
> B=Numeric.array(b)
> B.shape=(ak,)
newshape = [1] * len(A.shape)
newshape[k] = A.shape[k]
B.shape = newshape
result = A - B
wbf
More information about the Numpy-discussion
mailing list