Using numpy.apply

Posted by andylei on Stack Overflow See other posts from Stack Overflow or by andylei
Published on 2010-03-29T02:55:15Z Indexed on 2010/03/29 3:03 UTC
Read the original article Hit count: 408

Filed under:
|
|

What's wrong with this snippet of code?

import numpy as np
from scipy import stats

d = np.arange(10.0)
cutoffs = [stats.scoreatpercentile(d, pct) for pct in range(0, 100, 20)]
f = lambda x: np.sum(x > cutoffs)
fv = np.vectorize(f)

# why don't these two lines output the same values?
[f(x) for x in d] # => [0, 1, 2, 2, 3, 3, 4, 4, 5, 5]
fv(d)             # => array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Any ideas?

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy