【发布时间】:2020-10-03 10:44:03
【问题描述】:
我正在尝试将形状 (80000,) 的 numpy 数组转换为 (80000,55)
我有如下数据
[[1212,121,121],[12,122,111]]
转换此列表列表后,我得到了(2,) 的形状,但我想要像(2,3) 这样的形状怎么做。
【问题讨论】:
标签: python python-3.x pandas numpy
我正在尝试将形状 (80000,) 的 numpy 数组转换为 (80000,55)
我有如下数据
[[1212,121,121],[12,122,111]]
转换此列表列表后,我得到了(2,) 的形状,但我想要像(2,3) 这样的形状怎么做。
【问题讨论】:
标签: python python-3.x pandas numpy
In [68]: np.array([[1212,121,121],[12,122,111]] )
Out[68]:
array([[1212, 121, 121],
[ 12, 122, 111]])
In [69]: _.shape
Out[69]: (2, 3)
如果您得到类似 (2,) 的形状,可能是因为某些嵌套列表的形状不同。检查dtype 和shape。看看数组。
In [70]: np.array([[1212,121,121],[12,122,111,3]] )
Out[70]: array([list([1212, 121, 121]), list([12, 122, 111, 3])], dtype=object)
即将发布的版本将添加警告:
/usr/local/bin/ipython3:1: 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
#!/usr/bin/python3
【讨论】: