Forklift17
Forklift17

Reputation: 2477

numpy array into matlab

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.

Upvotes: 1

Views: 987

Answers (1)

Holt
Holt

Reputation: 37686

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

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

See the official tutorial for scipy.io.

Upvotes: 3

Related Questions