Getting some error while using pytorch lib

I got the below error while using pytorch. How to rectify this error? Is something wrong with the installation?

print(torch.version)
Traceback (most recent call last):

File “”, line 1, in
print(torch.version)

AttributeError: module ‘torch’ has no attribute ‘version

a=torch.tensor([10,10,10])

a
Out[8]: tensor([10, 10, 10])

a.mean()
Traceback (most recent call last):

File “”, line 1, in
a.mean()

RuntimeError: Can only calculate the mean of floating types. Got Long instead.

1 Like
import torch
print(torch.__version__)
a = torch.tensor([10, 10, 10]) # type: Long
print(a.float().mean())
b = torch.tensor([10., 10., 10.])  # type: Float
print(a.mean())

Use __version__ insteal of _version_.
Double underline.

Thanks for your response. Is it possible to calculate mean for Long data type without converting to Float?

1 Like