对应元素相乘 element-wise product: np.multiply(), 或 *
y1 = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2])
y2 = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2])
y1*y2
Out[8]: array([0, 0, 0, 1, 1, 1, 4, 4, 4])
np.multiply(y1,y2)
Out[9]: array([0, 0, 0, 1, 1, 1, 4, 4, 4])
np.dot()
x1 = np.array([[1, 2, 3], [4, 5, 6]])
x2 = np.array([[1, 2], [3, 4], [5, 6]])
np.dot(x1,x2)
Out[12]:
array([[22, 28],
[49, 64]])
转置
x1 = np.array([[1, 2, 3], [4, 5, 6]])
x1.T
Out[13]:
array([[1, 4],
[2, 5],
[3, 6]])
注意一维行数组的转置,无法成功,需要添加[]
y1 = np.array([0, 0, 0, 1, 1, 1, 2, 2, 2])
y1.T
Out[14]: array([0, 0, 0, 1, 1, 1, 2, 2, 2])
y2 = np.array([[0, 0, 0, 1, 1, 1, 2, 2, 2]])
y2.T
Out[17]:
array([[0],
[0],
[0],
[1],
[1],
[1],
[2],
[2],
[2]])