当前位置:网站首页>Centralized record of experimental problems

Centralized record of experimental problems

2022-04-23 20:47:00 NuerNuer

1.torch.repeat and tf.tile
Both functions will tensor Repeat the number of times for a certain dimension of :

a_ = torch.repeat(a, [x,y,x]) #a It's three-dimensional tensor, Put it 1,2,3 Dimension difference repeat x, y, z Time 
b_ = tf.tile(b, [c,d,e,f]) #b It's three-dimensional tensor, Put it 1,2,3,4 Dimension difference repeat a,b,c,d Time 

2.torch.diagonal and tf.diag_part
Extract the main diagonal element of the tensor

#torch
x = torch.randn(4,4)
tensor([[ 8.4527e-01,  1.9236e+00, -6.9886e-01, -4.1077e-01],
        [-1.4905e+00,  2.8126e-01,  9.9094e-02, -2.0024e-03],
        [-6.0617e-01,  1.0577e+00, -7.8548e-01,  2.0802e+00],
        [-7.9660e-01,  1.2871e+00, -3.5069e-01, -1.5513e+00]])

torch.diagonal(x)
# tensor([ 0.8453,  0.2813, -0.7855, -1.5513])

#tensorflow
a = tf.diag_part(b)

# To be continued 🤪

版权声明
本文为[NuerNuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210545522903.html