【发布时间】:2020-02-26 20:22:37
【问题描述】:
我正在尝试在 cython 程序中使用 np.where 来选择值在半径内的位置。通常这适用于 numpy,但使用 cython 我得到 p>
TypeError: 'tuple' 对象不能被解释为整数
def test(double[:,::1] array, double[:] point, double radius):
array = np.asarray(array)
idx = np.where(np.logical_and(np.greater_equal(array[:, 0], point[0] - radius), np.less_equal(array[:, 0], point[0] + radius)))
a = array[idx]
我尝试这样做但出错了
只有整数标量数组可以转换为标量索引
a = array[idx[0].astype(int)]
【问题讨论】:
-
我想你想要一个 = array[idx[0]]
-
这给出了一个类型错误:只有整数标量数组可以转换为标量索引.....因为我相信输出是数组的元组。我也试过做 a = array[idx[0].astype(int)]
标签: python numpy indexing cython where-clause