[Numpy-discussion] array.min() vs. min(array)

Arnd Baecker arnd.baecker at web.de
Wed Apr 26 23:49:06 CDT 2006


Moin,

On Wed, 26 Apr 2006, Travis Oliphant wrote:

> Ryan Krauss wrote:
> > I was spending some time trying to track down how to speed up an
> > algorithm that gets called a bunch of times during an optimization.  I
> > was startled when I finally figured out that most of the time was
> > wasted by using the built-in pyhton min function.  It turns out that
> > in my case, using array.min() (i.e. the method of the Numpy array) is
> > 300-500 times faster than the built-in python min function (i.e.
> > min(array)).
> >
> > So, thank you Travis and everyone who has put so much time into
> > thinking through Numpy and making it fast (as well as making sure it
> > is correct).
>
> The builtin min function is a bit confusing because it usually does work
> on NumPy arrays.  But, as you've noticed it is always slower because it
> uses the "generic sequence interface" that NumPy arrays expose.  So,
> it's basically not much faster than a Python loop.  In this case you are
> also being hit by the fact that scalarmath is not yet implemented (it's
> getting close though...)  so the returned array scalars are being
> compared using the bulky ufunc machinery on each element separately.
>
> In Python 2.5 we are going to have the same issues with the new any()
> and all() functions of Python.

I am just preparing a small text to collect such cases for the wiki.

However, I am not sure about a good name for such a page:
  http://www.scipy.org/Cookbook/Speed
  http://www.scipy.org/Cookbook/SpeedProblems
  http://www.scipy.org/Cookbook/Performance
?
(As usual, it is easy to start a page, than to properly maintain
it. OTOH things like this get lost very quickly, in particular with this
nice amount of traffic here).

In addition this also relates to
- profiling

  (For example I would like to add the contents of
  http://mail.enthought.com/pipermail/enthought-dev/2006-January/001075.html
  to the wiki at some point)
- psyco
- pyrex
- f2py
- weave
- numexpr
- ...

Presently much of this is listed in the Cookbook under
"Using NumPy With Other Languages (Advanced)",
and therefore the above "Python only" issues don't quite fit.
Any suggestions?

Best, Arnd






More information about the Numpy-discussion mailing list