
How to display PyTorch Tensor's value without its properties?
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
SHC
el 13 de Abr. de 2025
Respondida: Angelo Yeo
el 13 de Abr. de 2025
Hello,
When I run the following MATLAB code to define a tensor variable from PyTorch,
clear all; format compact
pe = pyenv();
a_tensor = py.torch.tensor([1, 2]);
a_tensor
MATLAB's output is as below:
a_tensor =
Python Tensor with properties:
T: [1x1 py.torch.Tensor]
data: [1x1 py.torch.Tensor]
device: [1x1 py.torch.device]
dtype: [1x1 py.torch.dtype]
grad: [1x1 py.NoneType]
grad_fn: [1x1 py.NoneType]
is_cpu: 1
is_cuda: 0
is_ipu: 0
is_leaf: 1
is_maia: 0
is_meta: 0
is_mkldnn: 0
is_mps: 0
is_mtia: 0
is_nested: 0
is_quantized: 0
is_sparse: 0
is_sparse_csr: 0
is_vulkan: 0
is_xla: 0
is_xpu: 0
itemsize: [1x1 py.int]
layout: [1x1 py.torch.layout]
name: [1x1 py.NoneType]
names: [1x1 py.tuple]
nbytes: [1x1 py.int]
ndim: [1x1 py.int]
output_nr: [1x1 py.int]
real: [1x1 py.torch.Tensor]
requires_grad: 0
retains_grad: 0
shape: [1x1 py.torch.Size]
volatile: 0
tensor([1., 2.])
The last line of the output shows actual values of the PyTorch tensor variable, but MATLAB shows all the properties of the tensor variable together.
Is there a way not to show the properties when I call the tensor variable name?
0 comentarios
Respuesta aceptada
Angelo Yeo
el 13 de Abr. de 2025
You can consider using tolist method. Converting a tensor to list will only leave the values in a list format.
clear all; format compact
pe = pyenv();
a_tensor = py.torch.tensor([1, 2]);
a_tensor.tolist()

0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!