尝试保存 .npy (numpy) 文件时出错



c:\python38\lib\site-packagesumpy\core_asarray.py:136:可见弃用警告:从参差不齐的嵌套序列(这是具有不同长度或形状的列表或元组的列表或元组或ndarray(创建ndarray是弃用的。如果你打算这样做,你必须在创建ndarray时指定'dtype=object' 返回数组(a, dtype, copy=False, order=order, subok=True(

我在堆栈溢出中遇到了一些问题,因此尝试为此升级scipy,但它显示了另一个错误:

错误:tensorflow 2.2.0 有 scipy==1.4.1; python_version>= "3",但你会有 scipy 1.5.0 不兼容。

有人能说出为什么会这样吗?

在 numpy 1.19dev 中,尝试从列表或数组的不规则列表创建数组开始显示此警告。 开发人员正试图解决一个已经存在了一段时间的问题。np.save保存数组,所以如果给定一个列表,它首先将其转换为数组:

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)

加载这样的数组也会产生错误:

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)

最新更新