Pytorch中的暗和Tensorflow中的轴有什么区别?

问题描述 投票:0回答:1

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

以上两行会得出相同的结果吗?或axis属性是否不同于dim]

tensorflow deep-learning pytorch tensor
1个回答
0
投票

是的,它们是相同的!

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])
© www.soinside.com 2019 - 2024. All rights reserved.