[SciPy-User] Sort b according to histogram(a)
Arthur M. Greene
amg@iri.columbia....
Wed Dec 16 15:53:18 CST 2009
Alan G Isaac wrote:
> On 12/16/2009 3:21 PM, Arthur M. Greene wrote:
>> x = (1,4,7), y = (200,100,1000), edges = (0,5,10)
>> counts = (2,1), ydata = (150,1000)
>
>
>>>> gety =
>>>>np.where(np.equal.outer(np.arange(1,len(edges)),np.digitize(x,edges)),y,0)
>>>> counts = (gety>0).sum(axis=1)
>>>> gety.sum(axis=1) / counts
> array([ 150, 1000])
>
The above looks like it will work (took a minute to figure out what
"outer" is doing), with one modification: y can be of either sign, so
counts becomes (gety!=0).sum(axis=1). y could also conceivably be
exactly zero, in which case the count would be missed even with the
above modification. But this is not too likely -- the raw values are
provided to many decimal places.
Thanks for the quick and helpful replies!
Arthur
*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*^*~*
Arthur M. Greene
The International Research Institute for Climate and Society
The Earth Institute, Columbia University
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/e6938d34/attachment.vcf
More information about the SciPy-User
mailing list