[Numpy-discussion] Indices returned by where()

Christian Marquardt christian at marquardt.sc
Wed Dec 6 10:28:39 CST 2006

Dear list,

apologies if the answer to my question is obvious...

Is the following intentional?


  Python 2.4 (#1, Mar 22 2005, 21:42:42)
  [GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.

  >>> import numpy as np
  >>> print np.__version__

  >>> x = np.array([1., 2., 3., 4., 5.])

  >>> idx = np.where(x > 6.)
  >>> print len(idx)

The reason is of course that where() returns a tuple of index arrays
instead of simply an index array:

  >>> print idx
  (array([], dtype=int32),)

Does that mean that one always has to explicitely request the first
element of the returned tuple in order to check how many matches were
found, even for 1d arrays? What's the reason for designing it that way?

Many thanks,


More information about the Numpy-discussion mailing list