如何隐蔽形状为n到n,m的数组

时间:2020-06-13 18:43:01

标签: python python-3.x pandas numpy

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

1 个答案:

答案 0 :(得分:4)

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,),则可能是因为某些嵌套列表的形状不同。检查dtypeshape。还要看一下数组。

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