Hi Alan, If you are only dealing with 1d array, What about:
np.nonzero(your_array)[0][:k] ? -Shawn On Tue, Feb 25, 2014 at 2:20 PM, Alan G Isaac <[email protected]> wrote: > Is there a shortcut version for finding the first (k) instance(s) of > nonzero entries? > I'm thinking of Matlab's `find(X,k)`: > http://www.mathworks.com/help/matlab/ref/find.html > Easy enough to write of course. > > I thought `flatnonzero` would be the obvious place for this, > but it does not have a `first=k` option. > Is such an option worth suggesting? > > Thanks, > Alan Isaac > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion > -- Yuxiang "Shawn" Wang Gerling Research Lab University of Virginia [email protected] +1 (434) 284-0836 https://sites.google.com/a/virginia.edu/yw5aj/
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
