# [SciPy-User] Sort b according to histogram(a)

Arthur M. Greene amg@iri.columbia....
Wed Dec 16 14:21:12 CST 2009

```This can be accomplished in a loop, but I'm hoping there is a more
efficient way: Starting with two 1-D arrays indexed the same, e.g.,

x0,x1,x2... y0,y1,y2...

the x's are first binned normally, i.e., a set of edges is defined and
each x that falls in a particular bin generates a count. (This can be
accomplished using histogram.) What I then need to do though, is find
the average value of the corresponding y's. Example:

x = (1,4,7), y = (200,100,1000), edges = (0,5,10)

Then

counts = (2,1), ydata = (150,1000)

Size of x or y is only about 500, but the procedure needs to be repeated
many times and looping makes the execution quite slow. I've been looking
at np.digitize, but haven't quite figured out how this (or some other
call I don't know) might be used to "vectorize" the process. Suggestions
appreciated!

Thx,

Arthur

*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*
Arthur M. Greene
The International Research Institute for Climate and Society
Monell Building, 61 Route 9W, Palisades, NY  10964-8000 USA
amg at iri . columbia . edu
*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*
-------------- next part --------------
A non-text attachment was scrubbed...
Name: amg.vcf
Type: text/x-vcard
Size: 174 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20091216/9d155f82/attachment.vcf
```

More information about the SciPy-User mailing list