max
full_like
import torch
a = torch.arange(3*2).reshape(3, 2)
print('a\n', a)
b = torch.full((3, 5), 0) # 生成一个三行五列全为0的tensor
print('b\n', b)
c = torch.full_like(a, 1) # 生成一个形如a的,值全为1的tensor
print('c\n', c)
输出结果:
a
tensor([[0, 1],
[2, 3],
[4, 5]])
b
tensor([[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0],
[0, 0, 0, 0, 0]])
c
tensor([[1, 1],
[1, 1],
[1, 1]])
argmax
shape:也就是获取最后的一个维度的数值
uniform_
clamp
a = torch.randint(0, 10, (5,3))
a
# 将a中的所有数据和5,8对比,小于5的改为5, 大于8的改为8,其他不变
torch.clamp(a, min=5, max=8)
full
其他参数讲解
dtype:即给tensor对象指定数据类型
layout:指定返回的layout
device: 主要是指定CPU和GPU
requires_grad:是否计算梯度,默认不计算
nonzero
官方解释
官方样例
argsort
flatten