[Numpy-discussion] Distance Formula on an Array

Eric Firing efiring@hawaii....
Sun Apr 26 15:49:24 CDT 2009


Ian Mallett wrote:
> It would be:
> numpy.where(array<d)
> right?

Almost.  where(cond) is equivalent to nonzero(cond), and both return 
tuples.  Assuming your array is 1-D, you can use:

numpy.where(array<d)[0]
numpy.nonzero(array<d)[0]
numpy.flatnonzero(array<d)

But do you really need the indices?  If what you need is values of some 
array at those locations, then index directly with the condition:

A_subset = A[array<d]

Eric


More information about the Numpy-discussion mailing list