遇到的问题:在pycharm中运行数组运算,出现警告
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.
经过查询,参考
VisibleDeprecationWarning , Creating an ndarray from ragged nested sequences... 警告怎么办 - xiake_shuoshuo - 博客园 (cnblogs.com)
https://www.cnblogs.com/yinshuo666/p/15014968.htmlVisible Deprecation Warning: Creating an ndarray from ragged nested sequences (which is list or tupl_球场书生的博客-CSDN博客
https://blog.csdn.net/qq_41917697/article/details/115698304对代码进行修改,添加dtype=object,警告消失。
问题解除。
import numpy as np
#举例
a = np.array([[0, 1, 2, 3, 4], [5, 6, 7, 8]], dtype=object)
在PyCharm中遇到numpy创建数组时的VisibleDeprecationWarning警告,该警告提示创建了不规则的嵌套序列。通过查阅资料并参照相关博客,解决方案是在创建数组时指定dtype为object。例如:`a = np.array([[0,1,2,3,4],[5,6,7,8]], dtype=object)`。应用此修改后,警告消除,问题得到解决。

2万+

被折叠的 条评论
为什么被折叠?



