torch.Tensor() new() received an invalid combination of arguments – got (list, dtype=torch.dtype)

We Are Going To Discuss About torch.Tensor() new() received an invalid combination of arguments – got (list, dtype=torch.dtype). So lets Start this Python Article.

torch.Tensor() new() received an invalid combination of arguments – got (list, dtype=torch.dtype)

  1. How to solve torch.Tensor() new() received an invalid combination of arguments – got (list, dtype=torch.dtype)

    Capitalization matters — in your top example, you have Tensor with uppercase T, but the documentation excerpt is talking about tensor with lowercase t.

  2. torch.Tensor() new() received an invalid combination of arguments – got (list, dtype=torch.dtype)

    Capitalization matters — in your top example, you have Tensor with uppercase T, but the documentation excerpt is talking about tensor with lowercase t.

Solution 1

Capitalization matters — in your top example, you have Tensor with uppercase T, but the documentation excerpt is talking about tensor with lowercase t.

Original Author Jan Pokorný Of This Content

Solution 2

As Jan’s answer said but here I will explain why
Tensor different from tensor

torch.Tensor is an alias for the default tensor type (torch.FloatTensor).
which is a CPU tensor, 32-bit floating-point so the type and device are predetermined.

#This will cause an Error, because Tensor has no dtype and device properties on it’s constructor

example_tensor = torch.Tensor(
    [
     [[1, 2], [3, 4]], 
     [[5, 6], [7, 8]], 
     [[9, 0], [1, 2]]
    ]
, dtype=torch.float32, device=device)

To move a tensor to a new device, you can write new_tensor = example_tensor.to(device) where the device will be either CPU or Cuda.
and to set new type you can use new_tensor.dtype=torch.float64 for example

     example_tensor = torch.Tensor(
    [
     [[1, 2], [3, 4]], 
     [[5, 6], [7, 8]], 
     [[9, 0], [1, 2]]
    ]
)
    new_tensor = example_tensor.to(device)
    new_tensor.dtype  #set or get dtype

this is from the documentation

A tensor (case senstive tensor not Tensor) of specific data type can be constructed by passing a torch.dtype and/or a torch.device to a constructor or tensor creation op:

cuda0 = torch.device('cuda:0')
torch.ones([2, 4], dtype=torch.float64, device=cuda0)

.

Original Author Mohamed Fathallah Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

ittutorial team

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment