如何将形状为 n 的数组转换为 n,m

Sar*_*j K 3 python numpy python-3.x pandas

我正在尝试将 numpy 形状数组转换(80000,)(80000,55) 我有如下数据 [[1212,121,121],[12,122,111]] 转换此列表列表后,我得到了形状,(2,)但我想要形状像(2,3)如何做。

hpa*_*ulj 5

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)
Run Code Online (Sandbox Code Playgroud)

如果您得到类似 (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)
Run Code Online (Sandbox Code Playgroud)

即将发布的版本将添加警告:

/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
Run Code Online (Sandbox Code Playgroud)