# numpy - 在NumPy中，向量的交叉积

``````
a = sc.array([[1], [2], [3]])
>>> a
[[1]
[2]
[3]]

b = sc.array([[4], [5], [6]])
>>> b
[[4]
[5]
[6]]

``````

``````
import numpy as np

np.cross(a, b)
ValueError: incompatible dimensions for cross product
(dimension must be 2 or 3)

``````

``````
np.cross(a.T, b.T)
[[-3 6 -3]]

``````

``````
In [17]: a = np.array([[1], [2], [3]])

In [18]: b = np.array([[4], [5], [6]])

In [19]: print a.shape,b.shape
(3, 1) (3, 1)

``````

``````
In [20]: np.cross(a,b,axis=0)
Out[20]:
array([[-3],
[ 6],
[-3]])

``````

``````
In [13]: a = np.array([1, 2, 3])

In [15]: b = np.array([4, 5, 6])

In [16]: np.cross(a, b)
Out[16]: array([-3, 6, -3])

In [17]: np.dot(a, b)
Out[17]: 32

``````

``````
In [26]: a = np.random.random((3, 4))

In [27]: b = np.random.random((3, 4))

In [28]: np.cross(a, b, axisa=0, axisb=0)
Out[28]:
array([[-0.34780508, 0.54583745, -0.25644455],
[ 0.03892861, 0.18446659, -0.36877085],
[ 0.36736545, 0.13549752, -0.32647531],
[-0.46253185, 0.56148668, -0.10056834]])

``````

``````
a = sc.array([1, 2, 3])
b = sc.array([4, 5, 6])

``````