[Numpy-discussion] Faster

Robert Kern robert.kern@gmail....
Fri May 2 22:54:11 CDT 2008


On Fri, May 2, 2008 at 10:48 PM, Keith Goodman <kwgoodman@gmail.com> wrote:
> On Fri, May 2, 2008 at 7:25 PM, Robert Kern <robert.kern@gmail.com> wrote:
>  >  In [5]: def kerndist(x):
>  >    ...:     N = x.shape[0]
>  >    ...:     x.flat[::N+1] = x.max()
>  >    ...:     ij = argmin(x.flat)
>  >    ...:     i, j = divmod(ij, N)
>  >    ...:     return i, j
>
>  I replaced
>
>  ij = argmin(x.flat)
>
>  with
>
>  x.argmin()
>
>  (they're the same in this context, right?) for a slight speed up. Now
>  I'm down to 1.9 seconds.

Yes, they're the same. I forgot that .argmin() flattened by default.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
 -- Umberto Eco


More information about the Numpy-discussion mailing list