python - 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
解决方案
如果认为您正在寻找的只是:
test = np.array([Diff, minVal, maxVal])
test.shape
(3, 6382, 7122)
推荐阅读
- python - 在 dict 中创建一个给定长度的随机数列表,每次引用它时都会重新处理
- json - 使用 VBA-JSON 从 API 中提取“错误:对象不支持此属性或方法”?
- python - 如何修复'ModuleNotFoundError:'kivy.garden.matplotlib.backend_kivyagg''
- html - Displaying the menu text when hovered
- jenkins - gitlab & jenkins,“找不到支持服务器的客户端构建器”错误
- java - 如何识别 AWS 中哪个 lambda 失败并重新运行它
- ios - Swift DispatchGroup causes error: [Firebase/Firestore][I-FST000001] Could not reach Cloud Firestore backend
- react-native - How do I specifically check a URL with NetInfo React-Native?
- angularjs - Wait for a request to finish before doing another one in angularjs
- ios - 适用于 iOS 的 Urban Airship Xamarin Native。自定义事件属性问题