[NumPy-Tickets] [NumPy] #2177: np.histogramdd does not work with reverse sorted bin sequence

NumPy Trac numpy-tickets@scipy....
Thu Jun 28 19:50:20 CDT 2012

#2177: np.histogramdd does not work with reverse sorted bin sequence
 Reporter:  andyfaff     |       Owner:  somebody   
     Type:  enhancement  |      Status:  new        
 Priority:  normal       |   Milestone:  Unscheduled
Component:  Other        |     Version:  1.6.1      
 Keywords:               |  
 The reference documentation for np.histogramdd does not specify that a
 supplied sequence for a bin specification needs to be sorted. Whilst this
 may be kind of obvious it should be stated.

 Moreover, and perhaps more importantly, it does not specify that the bin
 sequence is required to be  sorted in ascending order. Bin edges sorted in
 descending order do not work, the following results in a ValueError:

 >>> a = 0.1 * (np.arange(21.)-10)
 >>> a = a[::-1]
 >>> b = np.random.randn(100)
 >>> c,d = np.histogramdd(b, bins=[a])
 Warning: invalid value encountered in log10
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
 /site-packages/numpy/lib/function_base.py", line 314, in histogramdd
     decimal = int(-log10(dedges[i].min())) +6
 ValueError: cannot convert float NaN to integer

 The obvious workaround for me is to check if the bin edges are reverse
 sorted. If they are, reverse them and histogram, then reverse the output
 and bin edges.
 However, it would be a lot easier if histogramdd worked with arbitrarily
 sorted bin edges on each dimension.  This kind of requirement for binning
 is quite common when dealing with images.

Ticket URL: <http://projects.scipy.org/numpy/ticket/2177>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list