array + where return type: scalar vs. array

Travis Oliphant oliphant.travis at
Wed Oct 25 01:20:13 CDT 2006

Michael McNeil Forbes wrote:
> 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?
Yes, it's a bug.  The optimization for a[0,2] was being called in this 
case because the arrays with 1 element were being interpreted as 
integers.   I beefed-up the conversion check and fixed this in SVN.   
Thanks for the check.

Now both have the same shape.


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