1

Simple question: How do I save a NumPy array into a file that Matlab can easily read? I have found the scipy.io.savemat method but without any examples, I am having trouble figuring out how to use it. For instance, if I try this:

import numpy as np
import scipy.io as sio
theArray = np.array([0,1,2])
sio.savemat('theArray.mat', theArray)

Line 4 gives the error message "AttributeError: 'numpy.ndarray' object has no attribute 'items'". How do I fix this.

1 Answer 1

3

scipy.io.savemat wants a dict, not a numpy array:

sio.savemat('theArray.mat', {'theArray': theArray})

See the official tutorial for scipy.io.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.