Skip to content

Commit

Permalink
fix: use normal indexing instead of boolean indexing
Browse files Browse the repository at this point in the history
Boolean indexing results in an assignment bug when the result is a single element: TypeError: NumPy boolean array indexing assignment requires a 0 or 1-dimensional input, input has 2 dimensions

Closes #53
  • Loading branch information
chanshing committed Feb 1, 2024
1 parent f589667 commit 1afed4e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/stepcount/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,16 @@ def predict(self, X, groups=None, return_walk=False, return_step_times=False):
return

# check X quality
ok = ~(np.asarray([np.isnan(x).any() for x in X]))
ok = np.flatnonzero(~np.asarray([np.isnan(x).any() for x in X]))

X_ = X[ok]
W_ = self.wd.predict(X_, groups).astype('bool')
Y_ = np.zeros_like(W_, dtype='float')
Z_ = np.full_like(W_, fill_value=None, dtype=np.ndarray)

(Y_[W_], Z_[W_]) = batch_count_peaks(
X_[W_],
w_ = np.flatnonzero(W_)
(Y_[w_], Z_[w_]) = batch_count_peaks(
X_[w_],
self.sample_rate,
self.lowpass_hz,
self.find_peaks_params,
Expand Down

0 comments on commit 1afed4e

Please sign in to comment.