Access operations
作者:互联网
Access operations
Accessing elements inside tensors
Suppose we have the following tensors:
> t = torch.tensor([
[1,2,3],
[4,5,6],
[7,8,9]
], dtype=torch.float32)
> t.mean()
tensor(5.)
> t.mean().item() # we use the item() tensor method for scalar valued tensors to get a number
5.0
Do it with multiple values:
> t.mean(dim=0).tolist()
[4.0, 5.0, 6.0]
> t.mean(dim=0).numpy()
array([4., 5., 6.], dtype=float32)
标签:operations,5.0,tensor,dtype,torch,Access,tensors,mean 来源: https://www.cnblogs.com/xxxxxxxxx/p/11068463.html