简体   繁体   中英

Difference between Tensor and tensor

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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM