numpy/scipy/ipython:Failed to interpret file as a pickle

The numpy.load routine is for loading pickled .npy or .npz binary files, which can be created using numpy.save and numpy.savez, respectively. Since you have text data, these are not the routines you want.

You can load your comma-separated values with numpy.loadtxt.

import numpy as np
mean_data = np.loadtxt("/Users/daydreamer/data/mean", delimiter=',')

Full Example

Here’s a complete example (using StringIO to simulate the file I/O).

import numpy as np
import StringIO

s = """0,0.104553357966
1,0.213014562052
2,0.280656379048
3,0.0654249076288
4,0.312223429689
5,0.0959008911106
6,0.114207780917
7,0.105294501195
8,0.0900673766572
9,0.23941317105
10,0.0598239513149
11,0.541701803956
12,0.093929580526"""

st = StringIO.StringIO(s)
a = np.loadtxt(st, delimiter=',')

Now we have:

>>> a
array([[  0.        ,   0.10455336],
       [  1.        ,   0.21301456],
       [  2.        ,   0.28065638],
       [  3.        ,   0.06542491],
       [  4.        ,   0.31222343],
       [  5.        ,   0.09590089],
       [  6.        ,   0.11420778],
       [  7.        ,   0.1052945 ],
       [  8.        ,   0.09006738],
       [  9.        ,   0.23941317],
       [ 10.        ,   0.05982395],
       [ 11.        ,   0.5417018 ],

Leave a Comment