rougier / numpy-100

100 numpy exercises (with solutions)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Solution for Q10 is not entirely correct.

santiqwerty opened this issue · comments

10. Find indices of non-zero elements from [1,2,0,0,4,0] (★☆☆)

I think the solution should return at least an array with the indices. Something like this:

nz = np.nonzero([1,2,0,0,4,0])
print(nz[0])

which returns [0 1 4]

instead of

nz = np.nonzero([1,2,0,0,4,0])
print(nz)

which returns (array([0, 1, 4], dtype=int64),)

Thansk for your comment. The point of the question is to illustrate the use of nonzero. People are then free to use the results as they want.