0

I am working with Pytorch. But when I use tensor I got an error while I don't get any error when I use Tensor.

What is the difference between Tensor and tensor?

This is my example:

tns = torch.tensor([91,21,34,56]) tns.mean() 

I got this error:

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

Thanks in advance.

1 Answer 1

2

If you don't specify a dtype in torch.tensor() it infers this from the data. Since your data is all integers, it used Long.

torch.mean() can only be calculated for floats.

By default, torch.Tensor is an alias for torch.FloatTensor hence it automatically has dtype float (unless you change the default behaviour).

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, I got it and make it as below: tns = torch.tensor([91,21,34,56],dtype=torch.float64) tns.mean()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.