sahil pant
sahil pant

Reputation: 15

Error while trying to save .npy (numpy) file

c:\python38\lib\site-packages\numpy\core_asarray.py:136: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray return array(a, dtype, copy=False, order=order, subok=True)

I have gone through some questions in the stackoverflow so tried to upgrade scipy for this but it shows another error:

ERROR: tensorflow 2.2.0 has requirement scipy==1.4.1; python_version >= "3", but you'll have scipy 1.5.0 which is incompatible.

can someone tell why is this happening?

Upvotes: 1

Views: 4837

Answers (1)

hpaulj
hpaulj

Reputation: 231325

In numpy 1.19dev, trying to create an array from a ragged list of lists or array is starting to display this warning. Dev's are trying to fix a problem that's been around for a while. np.save saves arrays, so if given a list, it first turns it into an array:

In [227]: np.save('test.npy', [[1,2,3],[4,5]])                                          
/usr/local/lib/python3.6/dist-packages/numpy/core/_asarray.py:136: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
  return array(a, dtype, copy=False, order=order, subok=True)

Loading such an array also can produce an error:

In [228]: np.load('test.npy')                                                           
---------------------------------------------------------------------------    
ValueError: Object arrays cannot be loaded when allow_pickle=False

In [229]: np.load('test.npy', allow_pickle=True)                                        
Out[229]: array([list([1, 2, 3]), list([4, 5])], dtype=object)

Upvotes: 3

Related Questions