[Numpy-discussion] numpy scalars and savez -- bug?

Chris Barker - NOAA Federal chris.barker@noaa....
Wed Apr 17 19:28:11 CDT 2013


I've discovered somethign intertesting (bug?) with numpy scalars ans
savz. If I save a numpy scalar, then reload it, ot comes back as
rank-0 array -- similar, but not the same thing:

In [144]: single_value, type(single_value)
Out[144]: (2.0, numpy.float32)

In [145]: np.savez('test.npz', single_value=single_value)

In [146]: single_value2 = np.load('test.npz')['single_value']

In [147]: single_value, type(single_value)
Out[147]: (2.0, numpy.float32)

In [148]: single_value2, type(single_value2)
Out[148]: (array(2.0, dtype=float32), numpy.ndarray)

straight np.save has the same issue (which makes sense, I'm sure savez
uses the save code under the hood):

In [149]: single_value, type(single_value)
Out[149]: (2.0, numpy.float32)

In [150]: np.save('test.npy', single_value)

In [151]: single_value2 = np.load('test.npy')

In [152]: single_value2, type(single_value2)
Out[152]: (array(2.0, dtype=float32), numpy.ndarray)

This has been annoying, particular as rank-zero scalars are kind of a pain.



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception


More information about the NumPy-Discussion mailing list