array + where return type: scalar vs. array

Michael McNeil Forbes mforbes at
Wed Oct 25 00:25:02 CDT 2006

Could someone please explain the semantics of the following.

>>> from numpy import *
>>> a1 = array([1,2,3])
>>> a2 = array([[1,2,3]])
>>> a1[where(a1==3)],a2[where(a2==3)]
(array([3]), 3)

Why are 1-dimensional fundamentally different than N-dimensional arrays 
in this regard?  When there is a single match, N-d arrays always return 
a scalar whereas 1-d arrays return an array.

Is this a bug?


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list