Numpy
- 随机矩阵:
np.random.randn(d0, d1, d2, ...)
- 矩阵大小与形状:
np.ndarray.size
与np.dnarray.shape
Pytorch
- 随机矩阵:
torch.randn(d0, d1, d2, ...)
- 添加维度:
tensor.unsqueeze(0)
- 压缩维度:
tensor.squeeze(0)
- 按维度拼接tensor:
torch.cat(inputs, dim=0, ...)
- 维度堆叠:
torch.stack(inputs, dim=0)
- 张量排序索引:
tensor.sort(descending=True)
返回一个tensor为排序后的tensor, 一个为index_tensor - 矩阵元素夹逼:
tensor.clamp()
- 矩阵切割:
torch.chunk(tensor, chunks, dim)
- 矩阵复制:
torch.repeat(*size)
- 生成零矩阵:
torch.torch.zeros(5, 3, dtype=torch.long)
- 生产同形状的随机矩阵:
x = torch.randn_like(x, dtype=torch.float)
- 矩阵中函数名以’_’结尾的,如:
y.add_(x)
,运算结束后会改变y本身