简体   繁体   English

将2d numpy数组连接到3d numpy数组

[英]Concatenating 2d numpy arrays to a 3d numpy array

I have large set of 2d arrays which are being created with loop. 我有大量的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)

I want to convert these 2d arrays into one 3d array. 我想将这些2d数组转换为一个3d数组。

>>> arr_stacked.shape
(19, 129, 135)

Try using the simple numpy.array constructor : 尝试使用简单的numpy.array构造函数

import numpy as np

np.array([arcpy.RasterToNumPyArray(x) for x in list_imd])

Here is an example that works by me: 这是一个由我工作的例子:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM