1.torch.repeat和tf.tile
两个函数都是将tensor的某一维度进行制定次数的重复:
a_ = torch.repeat(a, [x,y,x]) #a是三维tensor,将其1,2,3维分别repeat x, y, z次
b_ = tf.tile(b, [c,d,e,f]) #b是三维tensor,将其1,2,3,4维分别repeat a,b,c,d次
2.torch.diagonal和tf.diag_part
提取张量的主对角线元素
#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)
#待续