1

I have large set of 2d arrays which are being created with loop.

>>> 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.

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

1 Answer 1

3

Try using the simple numpy.array constructor:

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.