VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tupl
提示: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
·
提示:
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)
解决方案
- 通过查资料可以知道应该是某处list转numpy array的时候出现长度不一致的情况。该文章中提出了第一种解决方式:降低numpy版本。但是用的开源代码需要该版本的numpy配合pytorch使用,所以不能更改版本。
- 这个警告应该是不影响正常结果,如果不想看可以在代码最前面加上在这里插入代码:
np.warnings.filterwarnings('ignore', category=np.VisibleDeprecationWarning)
- 这里我得代码中用到了很多numpy操作,所以我希望知道哪一行代码导致了出现这个警告。那么可以在最前面加上如下代码:
np.warnings.filterwarnings('error', category=np.VisibleDeprecationWarning)
这样就以error的形式输出报错信息。可以看到在哪一行代码出现的警告
总结:
这里我得理解:
np.warnings.filterwarnings('ignore', category=np.VisibleDeprecationWarning)
该行代码是把这个类型的警告忽略,因此不会再输出该警告信息
np.warnings.filterwarnings('error', category=np.VisibleDeprecationWarning)
该行代码应该是把这个类型的警告升级为error级别,然后以error级别进行输出,然后程序也会停止。
参考:
如有错误,请多指正!
更多推荐
所有评论(0)