小编chr*_*mos的帖子

对于排序数组来说,更快地替代 np.where

给定一个沿每行排序的大数组a,是否有比 numpy 更快的替代方法np.where来查找索引,其中min_v <= a <= max_v?\xc2\xa0 我想,利用数组的排序性质应该能够加快速度。

\n\n

np.where这是一个用于在大型数组中查找给定索引的设置示例。

\n\n
import numpy as np\n\n# Initialise an example of an array in which to search\nr, c = int(1e2), int(1e6)\na = np.arange(r*c).reshape(r, c)\n\n# Set up search limits\nmin_v = (r*c/2)-10\nmax_v = (r*c/2)+10\n\n# Find indices of occurrences\nidx = np.where(((a >= min_v) & (a <= max_v)))\n
Run Code Online (Sandbox Code Playgroud)\n

python arrays numpy where-clause

5
推荐指数
1
解决办法
845
查看次数

标签 统计

arrays ×1

numpy ×1

python ×1

where-clause ×1