import numpy as np
a = [1, 2, 3]
b = np.arange(1, 7).reshape(3, 2)
print(b)
# [[1 2]
# [3 4]
# [5 6]]
c = np.dot(a, b) # np.dot表示向量a与矩阵b的乘积[1×3]·[3×2]=[1×2]
print(c)
# [22 28]
d = np.insert(b, 2, a, axis=1)
# np.insert表示在矩阵b的基础上增加向量a,axis=1表示增加的向量以列的形式,2表示增加的向量a的索引为2
print(d)
# [[1 2 1]
# [3 4 2]
# [5 6 3]]
e = np.insert(b, 2, c, axis=0)
print(e)
# [[ 1 2]
# [ 3 4]
# [22 28]
# [ 5 6]]
【记录】np.dot以及np.insert用法
最新推荐文章于 2023-03-08 20:34:51 发布