首页 > 解决方案 > Min and Max values in n-dimension stack Python

问题描述

Hi have the following raster arrays stacked as numpy.stack with values between -30 and -2:

print(data.shape)
(3, 6382, 7122)

I want to produce a new numpy.array called minVal where I extract the minimun value for all the array cells (pixels) using all the layers of the stack

So if cell [24,78] in data[0], data[1], data[2] is -8, -30 , -15 respectivley, the retrived value should be -30

How should I proceed? I guess the same procedure should apply for the maximum value. In the end, I would like to stack minVal and maxVal together

So far I have tried with:

minVal = data.min(axis=0)
maxVal = data.max(axis=0)
Diff = maxVal - minVal

test = np.dstack(Diff, minVal, maxVal)

But I am getting the error:

TypeError: only integer scalar arrays can be converted to a scalar index

标签: pythonarraysnumpystackmin

解决方案


如果认为您正在寻找的只是:

test = np.array([Diff, minVal, maxVal])

test.shape
(3, 6382, 7122)

推荐阅读