VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
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. newArr = np.array(list_A)
原因
在list
里添加数组元素时没有正确索引,导致append
加入的是array
,后续将list
通过np.array进行转换时出现警告
解决方法
在x = B[0][i]
后添加[0]
也可能存在的原因:列表不规则,长短不一,在np.array(list_A)
之前检查list_A
Code
import numpy as npprint(numpy.__version__) # 1.22.2
A = np.arange(1, 25).reshape(4, 6)list_A = A.flatten().tolist()B = np.array([[[0, 2, 3, 4], [5, 6, 7, 8]]], dtype=np.int32)
print(A)
print(list_A)
"""
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. newArr = np.array(list_A)
"""
for i in range(B.shape[1]):x = B[0][i]# type(x) : <class 'numpy.ndarray'> DeprecationWarning# x = B[0][i][0]# solve type(x) : <class 'numpy.int32'># print(type(x))list_A.append(x)print(list_A)
newArr = np.array(list_A)
print(newArr)
VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences相关推荐
- VisibleDeprecationWarning , Creating an ndarray from ragged nested sequences... 警告怎么办?
我不是完美主义,但是至少,我在做实验的时候不能容忍有 warning 的出现. 今天使用 tensorflow.keras.datasets中的 imdb 数据集,使用 imdb.load_data( ...
- VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tupl
构造一个多维数组时,出现问题: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which i ...
- numpy之 警告VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
目录 警告 解决 警告 这是我写的读取npz文件的代码, datas = np.load("bsm.npz", allow_pickle=True) print(datas.fil ...
- Python学习:问题 VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a
遇到的问题:在pycharm中运行数组运算,出现警告 VisibleDeprecationWarning: Creating an ndarray from ragged nested sequenc ...
- 【Bug解决】VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
问题描述 VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or ...
- python报错 VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
python报错 VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences 报错原因:numpy中元素sh ...
- python numpy报错:VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
注意:标题中说是"报错",但是这事实上只是"警告".表依然可以正常导出. 今天遇到了这个问题,查到了这篇博文:https://blog.csdn.net/Aug ...
- 【Bug修复】VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences
问题描述: 在通过array()函数创建numpy数组时,因为array()函数是可以直接传入已有数据类型,所以,就直接使用dtype去查看类型,此时出现了一个警告. 代码: import numpy ...
- Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or nda
python报错 VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a lis ...
最新文章
- Android 中文 API (25) —— ZoomControls
- greta的问题及解决: LIBCMTD.lib(_wctype.obj) : error LNK2005: _iswspace already defined in xxx.obj...
- sqlplus命令行登录oracle数据库的N种方法盘点
- 825. 适龄的朋友
- 华为Mate 40手机将于国庆节发售:搭载全新5nm芯片
- c/c++教程 - 1.5 运算符
- lesson 7 strategies for efficient CUDA programming
- java架构说明书_JDBC 使用说明(流程、架构、编程)
- 告白气球--吉他教学
- python开发板卡驱动开发_一款能让你发挥无限创意的MicroPython开发板—TPYBoard开发板测...
- mybatis一简单one2one关系xml配置
- 94. autoload(2)
- 单片机c语言出租车计时程序,基于单片机的出租车计费(c语言
- 桌面客户端框架技术选型
- speedoffice(Word)怎么修改字体颜色呢
- Kali下卸载程序和安装程序的方法
- 智能音箱硬件和软件介绍[上] 硬件结构解析[Soomal]
- 用Keras构建神经网络的3种方法
- python中日期的数据类型_强制日期时间转换,强制日期时间数据类型,在pandas中使用read_表...
- 不会Ps?没关系,这些在线平面设计网站,很实用