2013-02-04 4 views

Répondre

3

Essayez np.where ou np.nonzero.

x = np.array([1, 0, 1, 1, 0, 0]) 
np.where(x)[0] # returns a tuple hence the [0], see help(np.where) 
# array([0, 2, 3]) 
x.nonzero()[0] # in this case, the same as above. 

Voir help(np.where) et help(np.nonzero).

Peut-être noter que dans la page np.where il mentionne que pour 1D x il est fondamentalement équivalent à votre longform dans la question.

+0

Je savais qu'il y avait un meilleur moyen! J'ai regardé "np.index *", mais je n'ai rien trouvé. –

Questions connexes