のリストとしてテンソルの形状を取得するには、V.shape
はtensorflow V.get_shape().as_list()
でV.PyTorchは:どのようにnumpyののint
の大きさのint型のタプルを与えることはV.の寸法の整数のリストを与えます
pytorchでは、V.size()
はサイズオブジェクトを与えますが、どのようにしてintに変換しますか?
のリストとしてテンソルの形状を取得するには、V.shape
はtensorflow V.get_shape().as_list()
でV.PyTorchは:どのようにnumpyののint
の大きさのint型のタプルを与えることはV.の寸法の整数のリストを与えます
pytorchでは、V.size()
はサイズオブジェクトを与えますが、どのようにしてintに変換しますか?
単にlist(var.size())
、例えば:あなたはNumPy
っぽい構文のファンなら
>>> import torch
>>> from torch.autograd import Variable
>>> from torch import IntTensor
>>> var = Variable(IntTensor([[1,0],[0,1]]))
>>> var
Variable containing:
1 0
0 1
[torch.IntTensor of size 2x2]
>>> var.size()
torch.Size([2, 2])
>>> list(var.size())
[2, 2]
、その後、tensor.shape
があります。
In [3]: ar = torch.rand(3, 3)
In [4]: ar.shape
Out[4]: torch.Size([3, 3])
# method-1
In [7]: list(ar.shape)
Out[7]: [3, 3]
# method-2
In [8]: [*ar.shape]
Out[8]: [3, 3]
# method-3
In [9]: [*ar.size()]
Out[9]: [3, 3]
P.S.:tensor.shape
はtensor.size()
のエイリアスですが、tensor.shape
はテンソルの属性ですが、tensor.size()
は関数です。これは、GPU対応のマシンでのみ動作します。
コードのどの部分がGPUマシンでのみ動作しますか? 'tensor.shape'? – rasen58