广播
for循环计算
代码语言:javascript复制a = np.array([1,2,3,4])
b = np.array([10,20,30,40])
c = a * b
输出[ 10 40 90 160]
切片
取值[0,0],[1,1],[2,0]
代码语言:javascript复制import numpy as np
x = np.array([[1, 2], [3, 4], [5, 6]])
y = x[[0,1,2], [0,1,0]]
print (y)
- start: end:step 切片范围,end默认-1
- [1,2] 切片索引
- … 取所有
向量计算
- dot对应的索引相乘
- vdot 向量点积
- matmul矩阵相乘