ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> numpy-discussion
numpy-discussion
[Numpy-discussion] Indices returned by where()
by Christian Marquardt other posts by this author
Dec 6 2006 8:28AM messages near this date
Re: [Numpy-discussion] pickling arrays: numpy 1.0 can't unpickle numpy 1.0.1 | Re: [Numpy-discussion] Indices returned by where()
Dear list,

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

Is the following intentional?

  $> python

  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__
  1.0

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

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

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,

  Christian

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@[...].org
http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thread:
Christian Marquardt
Charles R Harris

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved