1.dot函数的两个参数都是向量
import numpy as np
a1 = np.ones(10)
# array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
a2 = 2 * np.ones(10)
# array([2., 2., 2., 2., 2., 2., 2., 2., 2., 2.])
np.dot(a1, a2)
# 20.0
则dot函数实现的是向量的内积运算
2.dot函数的参数是向量和矩阵
a3 = 2 * np.ones(3)
# array([2., 2., 2.])
a4 = np.arange(15).reshape(3, 5)
# array([[ 0, 1, 2, 3, 4],
# [ 5, 6, 7, 8, 9],
# [10, 11, 12, 13, 14]])
# 此处a3做行向量, (1, 3)
np.dot(a3, a4)
# array([30., 36., 42., 48., 54.])
a5 = np.ones(5)
# array([1., 1., 1., 1., 1.])
# 此处a5做列向量,(5, 1)
np.dot(a4, a5)
# array([10., 35., 60.])
则向量会自动匹配实现矩阵的乘法
3.dot函数的参数都是矩阵
a4 = np.arange(15).reshape(3, 5)
# array([[ 0, 1, 2, 3, 4],
# [ 5, 6, 7, 8, 9],
# [10, 11, 12, 13, 14]])
a5 = np.arange(15).reshape(5, 3)
# array([[ 0, 1, 2],
# [ 3, 4, 5],
# [ 6, 7, 8],
# [ 9, 10, 11],
# [12, 13, 14]])
np.dot(a4, a5)
# array([[ 90, 100, 110],
# [240, 275, 310],
# [390, 450, 510]])
则进行矩阵乘法