python - 在掩码上求和:只有整数标量数组可以转换为标量索引
问题描述
我想生成一个圆形掩码,然后估计所述掩码内的总和:
import numpy as np
mask = np.zeros((1500,1500), dtype=bool)
y,x = np.ogrid[-750:750, -750:750]
mask[ x**2+y**2 <= 750**2 ] = True
tot = np.nansum(image[mask])
但是,我收到错误:
TypeError: only integer scalar arrays can be converted to a scalar index
图像是更长的代码的一部分,太长了,不能放在这里;另外,这不是产生错误的原因,它是由掩码的索引产生的。但是,尽管知道错误在哪里,但我无法以任何方式修复它。
我错过了什么?
解决方案
推荐阅读
- python - ModuleNotFoundError: 没有名为 '' 的模块。在同一个文件夹中
- python - Is there a way to play multiple mp3 files at once in pygame?
- c# - c# 中 volatile 字段的实际保证是什么?
- docker - Docker Debian nc command not found
- kotlin - Can't import dependencies for Kotlin multi platform common
- javascript - Can't access a property in an array of objects
- ios - react-native-text-detector 在 android 中运行良好,但为什么它在 iOS 中总是返回 false?
- python - 有没有办法在没有 Anaconda 的情况下运行 Jupyter Notebooks?
- ios - 在 Firestore 中使用点表示法的结果不一致(setData 与 updateData)
- c - C读取后无法写入文件