Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the data type of a PyTorch tensor

Tags:

pytorch

I understand that PyTorch tensors are homogenous, ie, each of the elements are of the same type.

How do I find out the type of the elements in a PyTorch tensor?

like image 201
Tom Hale Avatar asked Nov 19 '18 12:11

Tom Hale


1 Answers

There are three kinds of things:

dtype                   || CPU tensor               || GPU tensor

torch.float32              torch.FloatTensor           torch.cuda.FloatTensor

The first one you get with print(t.dtype) if t is your tensor, else you use t.type() for the other two.

like image 116
prosti Avatar answered Oct 16 '22 02:10

prosti