numpy numpy.cross Multiple Cross Products with One Call

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Either input can be an array of 3- (or 2-) element vectors.

>>> a=np.array([[1,0,0],[0,1,0],[0,0,1]])
>>> b=np.array([1,0,0])
>>> np.cross(a,b)
array([[ 0,  0,  0],
       [ 0,  0, -1],
       [ 0,  1,  0]])

The result in this case is array([np.cross(a[0],b), np.cross(a[1],b), np.cross(a[2],b)])

b can also be an array of 3- (or 2-) element vectors, but it must have the same shape as a. Otherwise the calculation fails with a "shape mismatch" error. So we can have

>>> b=np.array([[0,0,1],[1,0,0],[0,1,0]])
>>> np.cross(a,b)
array([[ 0, -1,  0],
       [ 0,  0, -1],
       [-1,  0,  0]])

and now the result is array([np.cross(a[0],b[0]), np.cross(a[1],b[1]), np.cross(a[2],b[2])])



Got any numpy Question?