1

I have several huge arrays, and I am using np.save and np.load to save each array or dictionary in a single file and then I reload them, in order not to compute them another time as follows.

save(join(dir, "ListTitles.npy"), self.ListTitles)
self.ListTitles = load(join(dir,"ListTitles.npy"))

The problem is that when I try to use them afterwards, I have errors like (field name not found) or (len() of unsized object). For example:

 len(self.ListTitles) or when accessing a field of a dictionary return an error.

I don't know how to resolve this. Because when I simply use this code, it works perfectly:

M = array([[1,2,0], [3,4,0], [3,0,1]])
vector = zeros(3529)
save("M.npy", M)
save("vector.npy", vector)
vector = load("vector.npy")
B = load("M.npy")
print len(B)
print len(vector)
2
  • What is self.ListTitles? An array, list, dictionary,...? Commented Feb 18, 2015 at 6:36
  • is a dictionnary like {'repondr': 0, 'cytometr': 2, 'dynamic': 3}, I also have some non-numpy lists and some numpy arrays as well. Thank you in advance ! Commented Feb 18, 2015 at 7:11

1 Answer 1

3

numpy's save and load functions are for numpy arrays, not for general Python data like dicts. Use the pickle module to save to file, and reload from file, most kinds of Python data structures (there are alternatives like dill which are however not in the standard library -- I'd recommend sticking with standard pickle unless it gives you specific problems).

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

1 Comment

I think the scipy.io.savemat (matlab format) can also handle other objects.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.