Indices of Non-Zero Elements

easynumpy_indexing

Implement nonzero_indices(x).

Given a 1D array x, return a 1D array of the indices where x is non-zero, in increasing order. No for/while loops.

Constraints
  • no scipy, sklearn
  • no for/while loops

Your solution

Edit nonzero_indices and run the real pytest suite in your browser — no install required. Your code is saved locally.

⌘/Ctrl + ↵

Loading the Python runtime (first run only)…

Hints

Hint 1

np.nonzero(x) returns the indices of the non-zero entries (take [0] for 1D).