>>> import torch>>> a = torch.Tensor((1,2))>>> b = torch.Tensor((3,2))>>> a*btensor([3., 4.])>>> a/btensor([0.3333, 1.0000])>>> a==btensor([False, True])>>> a==1tensor([ True, False])>>> c = torch.Tensor((3,2,1)) >>> a==cTraceback (most recent call last): File "<stdin>", line 1, in <module>RuntimeError: The size of tensor a (2) must match the size of tensor b (3) at non-singleton dimension 0
>>> a = torch.Tensor((1,2))>>> print("yes" if a else "no")Traceback (most recent call last): File "<stdin>", line 1, in <module>RuntimeError: Boolean value of Tensor with more than one value is ambiguous>>> a.all()tensor(False)>>> a.any()tensor(True)
これはつまり、張量変数が設定されているかどうかを判定するには、if a: ではなく if a is not None: を使用する必要があることを意味します。