Hi
quio
cheng
!
To convert a '
matlab.double
' variable to a 'Tensor' in Python, you can use the '
numpy
' library to first convert the
matlab.double
to a NumPy array, and then convert the 'NumPy array' to a 'Tensor'.
Start by loading your
matlab.double
array:
myData = eng.eval(
"load('{}','cluster_class','par')"
.format(
'sampleData.mat'
))
With MATLAB R2022a and later, you can convert
matlab.double
directly to a
numpy
array:
a = np.array(myData[
'cluster_class'
])
if you are using
pytorch
then
x_tensor = torch.tensor(a)
if you are using
tensorflow
then
data_tf = tf.convert_to_tensor(a)
Hope this helps!
Thank you.
Find the treasures in MATLAB Central and discover how the community can help you!