[英]Python Numpy beginner: getting an array with a shape ((M,N),(M,N))
[英]How to covert array of shape n, to n,m
我正在嘗試將形狀(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)
如果你得到像 (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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.