![](/img/trans.png)
[英]Concatenating 'N' 2D arrays in NumPy with varying dimensions into one 3D array
[英]Concatenating 2d numpy arrays to a 3d numpy array
我有大量的2d數組,用循環創建。
>>> for x in list_imd:
... arr = arcpy.RasterToNumPyArray(x)
... print arr.shape
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
(129, 135)
我想將這些2d數組轉換為一個3d數組。
>>> arr_stacked.shape
(19, 129, 135)
嘗試使用簡單的numpy.array
構造函數 :
import numpy as np
np.array([arcpy.RasterToNumPyArray(x) for x in list_imd])
這是一個由我工作的例子:
a = np.array([[1, 2, 3], [3, 4, 5]])
>>> np.array([a, a]).shape
(2, 2, 3)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.