The Tensor.type(dtype=None) function has the ability to cast the tensor to the given dtype as a parameter. If dtype parameter is not provided, it just returns the dtype of the tensor. So, the difference is the added functionality of casting.

Also, If the casting is performed to a new type, then the function returns a copy of the tensor.

Answer from Vishnudev Krishnadas on Stack Overflow
🌐
Data Science Weekly
datascienceweekly.org › tutorials › tensor-to-float-convert-a-pytorch-tensor-to-a-floating-number-data-type
Tensor To Float: Convert a PyTorch Tensor To A Floating Number Data Type
To confirm that it's a PyTorch integer tensor, let's use the PyTorch dtype method to check the tensor's data type attribute ... We can see that it's "torch.int64" which is a 64-bit integer that is signed.
🌐
Shanakadesoysa
notes.shanakadesoysa.com › PyTorch › tensor_basics
PyTorch Tensor Basics - Notes
Alternatively you can set the type by the tensor method used. For a list of tensor types visit https://pytorch.org/docs/stable/tensors.html · x = torch.FloatTensor([5,6,7]) print(x) print(x.dtype) print(x.type())
🌐
Pytorchcourse
pytorchcourse.com › 01-tensors › 03_data_types_and_devices
DTypes & Devices: Choose Your Weapons - PyTorch Course
October 26, 2025 - torch.uint8: An 8-bit unsigned integer, representing values from 0 to 255. The undisputed king for storing image data, where each pixel in an RGB channel has a value in this exact range!
🌐
Codecademy
codecademy.com › docs › pytorch › tensor operations › specifying data types
PyTorch | Tensor Operations | Specifying Data Types | Codecademy
January 13, 2025 - To specify a data type in a PyTorch tensor, use the dtype parameter when creating a tensor or the .to() method for converting an existing one. torch.tensor(data, dtype=torch.<data_type>) data: The input data used to create the tensor.
🌐
PyTorch
docs.pytorch.org › reference api › torch.tensor › torch.tensor.type
torch.Tensor.type — PyTorch 2.11 documentation
January 1, 2023 - Returns the type if dtype is not provided, else casts this object to the specified type.
🌐
GitHub
github.com › pytorch › pytorch › issues › 72365
How is Tensor.type supposed to work with strings? · Issue #72365 · pytorch/pytorch
February 4, 2022 - def type(self: T, dst_type: Union[dtype, str]) -> T: r"""Casts all parameters and buffers to :attr:`dst_type`. .. note:: This method modifies the module in-place. Args: dst_type (type or string): the desired type Returns: Module: self """ However, it seems not to work if dst_type is passed as a string. I would expect it to work the same way as NumPy's astype(...) I did not find usage examples around. ... import torch import numpy as np x = torch.rand(5,5) y = np.random.rand(5,5) # conversion using the relevant dtype works x.type(torch.float16) y.astype(np.float16) # np supports also dtype passed as strings y.astype("float16") # however, torch does not x.type("float16") # also this does not work x.type("torch.float16")
Author   marcozullich
🌐
PyTorch
docs.pytorch.org › intro › learn the basics › tensors
Tensors — PyTorch Tutorials 2.12.0+cu130 documentation
July 20, 2022 - tensor = torch.rand(3,4) print(f"Shape of tensor: {tensor.shape}") print(f"Datatype of tensor: {tensor.dtype}") print(f"Device tensor is stored on: {tensor.device}") Shape of tensor: torch.Size([3, 4]) Datatype of tensor: torch.float32 Device tensor is stored on: cpu ·
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-get-the-data-type-of-a-pytorch-tensor
How to Get the Data Type of a Pytorch Tensor? - GeeksforGeeks
July 21, 2021 - # import torch import torch # create a tensor with float type a = torch.tensor([100, 200, 2, 3, 4], dtype=torch.float) # display tensor print(a) # display data type print(a.dtype) # create a tensor with double type a = torch.tensor([1, 2, -6, -8, 0], dtype=torch.double) # display tensor print(a) # display data type print(a.dtype) ... tensor([100., 200., 2., 3., 4.]) torch.float32 tensor([ 1., 2., -6., -8., 0.], dtype=torch.float64) torch.float64
Find elsewhere
🌐
GitHub
alband.github.io › doc_view › tensors.html
torch.Tensor — PyTorch master documentation
dtype (torch.dtype, optional) – the desired type of returned tensor. Default: if None, same torch.dtype as this tensor. device (torch.device, optional) – the desired device of returned tensor.
🌐
TutorialsPoint
tutorialspoint.com › how-to-get-the-data-type-of-a-tensor-in-pytorch
How to get the data type of a tensor in PyTorch?
November 6, 2021 - Integer tensor: torch.int32 Float tensor: torch.float64 Boolean tensor: torch.bool · Use the .dtype attribute to check any PyTorch tensor's data type.
🌐
ProjectPro
projectpro.io › recipes › what-is-torch-tensor-explain-with-example
What is a Torch Tensor? -
October 20, 2023 - The Torch tensor is a multi-dimensional matrix containing a single data type element. Ten tensor types are defined by the torch with CPU and GPU variants. The different tensor types are: ... Data type - 8-bit integer (unsigned) dtype - torch.uint8 ...
🌐
APXML
apxml.com › courses › getting-started-with-pytorch › chapter-2-advanced-tensor-manipulations › tensor-data-types
PyTorch Tensor Data Types | Float, Int
You can also explicitly specify the dtype during tensor creation: # Create a tensor with 64-bit floating point numbers c = torch.tensor([1.0, 2.0], dtype=torch.float64) print(f"\nTensor c: {c}") print(f"dtype of c: {c.dtype}") # Create a tensor with 32-bit integers d = torch.ones(2, 2, dtype=torch.int32) print(f"\nTensor d:\n{d}") print(f"dtype of d: {d.dtype}")