[Numpy-discussion] vectorized function inside a class
Stefan van der Walt
stefan at sun.ac.za
Wed Aug 8 12:08:19 EDT 2007
On Wed, Aug 08, 2007 at 08:54:18AM -0700, Timothy Hochberg wrote:
> Don't use vectorize? Something like:
>
> def f(self,y):
> return np.where(y > self.x, y, self.x)
A one-liner, cool. Benchmarks on some other methods:
Method 1: N.where
100 loops, best of 3: 9.32 ms per loop
Method 2: N.clip
10000000 loops, best of 3: 112 ns per loop
100 loops, best of 3: 3.33 ms per loop
Method 3: N.putmask
100 loops, best of 3: 5.95 ms per loop
Method 4: fancy indexing
100 loops, best of 3: 5.09 ms per loop
Cheers
Stéfan
More information about the NumPy-Discussion
mailing list