File size: 528 Bytes
5522a00 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import pickle
import scipy.io
import torch
import numpy as np
# Load the .p file
with open('filename.p', 'rb') as file:
tensor_data = pickle.load(file) # This should be a PyTorch tensor
# Ensure it is a PyTorch tensor
if isinstance(tensor_data, torch.Tensor):
tensor_data = tensor_data.numpy() # Convert to NumPy array
# Save as a MATLAB file
scipy.io.savemat('filename.mat', {'tensor': tensor_data})
#%% In MATLAB
# data = load('filename.mat');
# tensor = data.tensor; % Access the variable
|