Pytorch 中的 dim 和 Tensorflow 中的 axis 有什么区别?

What's the difference between dim in Pytorch and axis in Tensorflow?

我有两条线,我想知道它们是否会产生相同的输出?
在张量流中:tf.norm(my_tensor, ord=2, axis=1)
在火炬中:torch.norm(my_tensor, p=2, dim=1)
假设 my_tensor 的形状是 [100,2]

以上两行会给出相同的结果吗?还是axis属性和dim不一样?

是的,它们是一样的!

import tensorflow as tf
tensor = [[1., 2.], [4., 5.], [3., 6.], [7., 8.], [5., 2.]]
tensor = tf.convert_to_tensor(tensor, dtype=tf.float32)
t_norm = tf.norm(tensor, ord=2, axis=1)
print(t_norm)

输出

tf.Tensor([ 2.236068   6.4031243  6.708204  
            10.630146   5.3851647], shape=(5,), dtype=float32)
import torch
tensor = [[1., 2.], [4., 5.], [3., 6.], [7., 8.], [5., 2.]]
tensor = torch.tensor(tensor, dtype=torch.float32)
t_norm = torch.norm(tensor, p=2, dim=1)
print(t_norm)

输出

tensor([ 2.2361,  6.4031,  6.7082, 10.6301,  5.3852])