简体   繁体   English

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

[英]How to covert array of shape n, to n,m

I'm trying convert numpy array of shape (80000,) to (80000,55) I'm having the data like below [[1212,121,121],[12,122,111]] After convert this list of list I'm getting the shape of (2,) but I wanna have shape like (2,3) how to do it.我正在尝试将形状(80000,)的 numpy 数组转换为(80000,55)我有如下数据[[1212,121,121],[12,122,111]]转换此列表列表后,我得到了形状(2,)但我想要像(2,3)这样的形状怎么做。

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)

If you are getting a shape like (2,), it's probably because some of the nested lists differ in shape.如果你得到像 (2,) 这样的形状,可能是因为一些嵌套列表的形状不同。 Check the dtype as well as the shape .检查dtype以及shape Look at the array as well.也看看数组。

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)

An upcoming version will add a warning:即将发布的版本将添加警告:

/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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python Numpy初学者:获取形状为((M,N),(M,N))的数组 - Python Numpy beginner: getting an array with a shape ((M,N),(M,N)) 如何在形状为 (n,m) 的 numpy 数组的选定列中添加元素? - How to add element in a selected column of a numpy array of shape (n,m)? 如何创建一个沿着特定(第三)轴的3D(shape = m,n,o)数组,索引由2D数组(shape = m,n)给出? - How to create a 3D (shape=m,n,o) array with ones along a specific (third) axis, the indices are given by a 2D array (shape=m,n)? Python Numpy 将数组重塑为具有少于 m*n 个元素的 (m,n) 形状 - Python Numpy Reshape an array to (m,n) shape that has less than m*n elements 从形状(m,n)的numpy数组创建Pandas系列 - Create Pandas Series from numpy array of shape (m, n) 如何在numpy数组形状(n,)或(n,1)中旋转数字? - How do you rotate the numbers in an numpy array of shape (n,) or (n,1)? 如何将一系列形状为 (n,1) 的数字作为 n 个唯一数字的数组重复 4 次,形状为 (n,1) - How to repeat a series of numbers with shape (n,1) as an array of n unique numbers repeated by 4 times with a shape of (n,1) 将大小为(n,n,m)的数组转换为(None,n,n,m) - converting an array of size (n,n,m) to (None,n,n,m) 如何展平(n,)形状numpy数组 - how to flatten (n, ) shape numpy array 如何在numpy中将(n,)数组添加到(n,m)数组? - How to add (n,) array to (n,m) array in numpy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM