[Numpy-discussion] saving 3d array

Matthew Brett matthew.brett@gmail....
Sat Jun 15 07:28:43 CDT 2013


Hi,

On Sat, Jun 15, 2013 at 1:22 PM, Sudheer Joseph
<sudheer.joseph@yahoo.com> wrote:
> Dear Experts,
>                     I was trying to save results of eof analysis to an npz file and see that it is not possible to save a 3d array as npz file variable. Is this true even today or are there developments which make this possible?  I am able to save all other variables except the 3d array.
> with best regards,
> Sudheer
>
>  eof1.shape
> Out[61]: (10, 140, 180)
>
> pc1.shape
> Out[62]: (2192, 10)
>
> x.shape
> Out[63]: (140, 180)
>
> np.savez(outf,pcs=pc1,x=x,y=y,clevs=clevs)
>
> works fine
> but below do not
>
> np.savez(outf,eof1=eof1)
> ---------------------------------------------------------------------------
> NotImplementedError                       Traceback (most recent call last)
> /home/sjo/RAMA_20120807/adcp/<ipython-input-66-fe5940e44a77> in <module>()
> ----> 1 np.savez(outf,eof1=eof1)
>
> /usr/local/lib/python2.7/dist-packages/numpy-1.7.0-py2.7-linux-x86_64.egg/numpy/lib/npyio.pyc in savez(file, *args, **kwds)
>     514
>     515     """
> --> 516     _savez(file, args, kwds, False)
>     517
>     518 def savez_compressed(file, *args, **kwds):
>
> /usr/local/lib/python2.7/dist-packages/numpy-1.7.0-py2.7-linux-x86_64.egg/numpy/lib/npyio.pyc in _savez(file, args, kwds, compress)
>     573             fid = open(tmpfile, 'wb')
>     574             try:
> --> 575                 format.write_array(fid, np.asanyarray(val))
>     576                 fid.close()
>     577                 fid = None
>
> /usr/local/lib/python2.7/dist-packages/numpy-1.7.0-py2.7-linux-x86_64.egg/numpy/lib/format.pyc in write_array(fp, array, version)
>     407     else:
>     408         if isfileobj(fp):
> --> 409             array.tofile(fp)
>     410         else:
>     411             # XXX: We could probably chunk this using something like
>
>
> /usr/local/lib/python2.7/dist-packages/numpy-1.7.0-py2.7-linux-x86_64.egg/numpy/ma/core.pyc in tofile(self, fid, sep, format)
>    5380
>    5381         """
> -> 5382         raise NotImplementedError("Not implemented yet, sorry...")
>    5383
>    5384     def toflex(self):
>
> NotImplementedError: Not implemented yet, sorry...

>From the traceback, it looks as though this is an error saving a
masked array, rather than a 3D array.   Can you convert to a
non-masked array before saving?  Maybe you could save the mask and the
unmasked array separately?

Best,

Matthew


More information about the NumPy-Discussion mailing list