Skip to content

Commit f38bace

Browse files
committed
Optimize _calc_groups with np.digitize for performance
1 parent 5d29244 commit f38bace

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

skgstat/Variogram.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1990,11 +1990,11 @@ def _calc_groups(self, force=False):
19901990
bin_edges = self.bins
19911991
d = self.distance
19921992

1993-
# -1 is the group fir distances outside maxlag
1994-
self._groups = np.ones(len(d), dtype=int) * -1
1993+
# use digitize for efficient binning
1994+
self._groups = np.digitize(d, bin_edges)
19951995

1996-
for i, bounds in enumerate(zip([0] + list(bin_edges), bin_edges)):
1997-
self._groups[np.where((d >= bounds[0]) & (d < bounds[1]))] = i
1996+
# -1 is the group for distances outside maxlag
1997+
self._groups[self._groups == len(bin_edges)] = -1
19981998

19991999
def clone(self):
20002000
"""Deep copy of self

0 commit comments

Comments
 (0)