[Numpy-discussion] cross product of two 3xn arrays
Travis Oliphant
oliphant.travis at ieee.org
Thu Feb 16 06:21:15 EST 2006
Gary Ruben wrote:
> I expect to get from this
>
> In [21]: a=array([[[1],[2],[3]],[[4],[5],[6]],[[7],[8],[9]]])
> In [22]: b=array([[[1],[2],[4]],[[4],[5],[7]],[[7],[8],[10]]])
>
> the solution
>
> Out[24]:
> array([[[ 2],
> [-1],
> [ 0]],
>
> [[ 5],
> [-4],
> [ 0]],
>
> [[ 8],
> [-7],
> [ 0]]])
Why do you expect to get this solution with axis=0? Remember axis=0
thinks the vectors are formed in the 0th dimension. Thus a[:,0,0] and
a[:,1,0] and a[:,2,0] are the vectors you are using.
You appear to be thinking of the vectors in the axis=1 dimension where
the vectors would be
a[0,:,0], a[1,:,0], a[2,:,0]
But this is specified with axis=1 (there is a single axis argument
available now in SVN which means
axisa=axisb=axisc=axis)
Thus,
cross(a,b,axis=1)
Gives the solution I think you are after.
-Travis
More information about the NumPy-Discussion
mailing list