0

Is there a way to convert a 3D numpy Array in Python to a 3D Matrix in Matlab?

I only found a way to convert a 2D matrix by saving it as a dictionary using savemat function in scipy.io. But nothing clear about how to covert a 3D numpy Array in Python to a 3D Matrix in Matlab

IoT
  • 563
  • 1
  • 7
  • 23
  • Does this not work? https://stackoverflow.com/questions/10997254/converting-numpy-arrays-to-matlab-and-vice-versa You could just reshape the 3D matrix to 2D and then back – anandsun Jan 22 '18 at 16:52
  • You can save it directly as 3D, nothing special is required. – bnaecker Jan 22 '18 at 16:54
  • 1
    @anandsun yes that works. There is no dimension limit in any of the languages – Ander Biguri Jan 22 '18 at 16:56
  • @bnaecker can you clarify how to do that? Dictionary only takes two dimensions (X as the keys and Y as values) – IoT Jan 22 '18 at 16:56
  • 1
    @IoT there is no difference between 1D, 2D, 3D, 4D, 5D or ND. – Ander Biguri Jan 22 '18 at 16:59
  • 2
    @IoT You misunderstand the dictionary argument. It's a dict whose keys are the *names* of the arrays as saved in the file, and whose values are the actual arrays in Python that are to be saved into the file. Those arrays can be of arbitrary dimension. They will be saved correctly and loaded correctly in Matlab. – bnaecker Jan 22 '18 at 17:01
  • https://stackoverflow.com/questions/1095265/matrix-from-python-to-matlab Another dupe – Ander Biguri Jan 22 '18 at 17:04
  • In the text it seems you want to convert np.array to dict and then save that. Just save the np.arrays as in the provided links. – Ander Biguri Jan 22 '18 at 17:10

0 Answers0