首页 > 解决方案 > 在掩码上求和:只有整数标量数组可以转换为标量索引

问题描述

我想生成一个圆形掩码,然后估计所述掩码内的总和:

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

图像是更长的代码的一部分,太长了,不能放在这里;另外,这不是产生错误的原因,它是由掩码的索引产生的。但是,尽管知道错误在哪里,但我无法以任何方式修复它。

我错过了什么?

标签: pythonnumpyindexingtypeerrormask

解决方案


推荐阅读