norm范数
与normalize(batch_norm)不同
Vector Norm与Matrix Norm计算的不同
计算没太看懂,后面算的时候再看
min,max,prod,mean等
prod()是累乘
mean()是均值
min最小值
argmin,argmax索引
没有指定纬度,就打平求
argmin(dim=):在dim纬度上求最小值,得到index
dim,keepdim
max(dim=):返回最大值和索引
a=torch.randn(4,10)
print(a)
a.argmax(dim=1)
b,c=a.max(dim=1)
print(b,c)
tensor([[-1.0555e+00, -4.7406e-01, -1.7884e+00, 4.7256e-01, 1.2359e-01,
-1.1320e-02, 8.9937e-01, -3.7503e-01, 4.4091e-01, -1.0220e+00],
[-4.5359e-01, 2.1482e-01, -1.1953e+00, 9.0963e-03, -7.7804e-01,
8.5170e-01, -9.5218e-01, 7.8373e-01, -5.0498e-01, 2.7409e-01],
[ 1.0214e+00, 1.0886e+00, -1.1839e+00, 2.0071e+00, 7.4919e-01,
3.9205e-01, -5.6472e-01, -1.3950e+00, -1.6764e+00, 2.4113e+00],
[ 8.6189e-01, 1.6097e-03, -2.1737e-01, 9.0528e-01, -1.4958e+00,
-1.1681e-01, 7.7766e-01, 1.0796e+00, 4.0260e-02, -1.3723e+00]])
tensor([0.8994, 0.8517, 2.4113, 1.0796]) tensor([6, 5, 9, 7])
max(dim=,keepdim=true):就会保留纬度,本来是[4],true之后是[4,1]
topk,kthvalue
topk(k,dim):返回dim上前k大的数和索引
topk(k,dim,largest=False):前k小
kthvalue(k,dim):dim纬度上第k大的值和索引
比较
- 符号
- torch.eq(a,b):对应位置比较,返回tensor
- torch.equal(a,b):返回true,false,全比较
where
where(condition,a,b)
if condition, ai
else bi
ond=torch.rand(2,2)
print(cond)
a=torch.full([2,2],0)
b=torch.full([2,2],1)
a,b
torch.where(cond>0.5,a,b)
tensor([[0.4939, 0.6974],
[0.8966, 0.9464]])
20
tensor([[1, 0],
[0, 0]])