[Numpy-discussion] histogram using decending range -- what do the results mean?

Mark.Miller mpmusu at cc.usu.edu
Fri Oct 5 18:14:47 EDT 2007


My bad...I also note that I forgot to decrement the descending list in 
my example.  Ignore....

Robert Kern wrote:
> Mark.Miller wrote:
>> Check how you're implementing the histogram function with respect to 
>> that range statement.  It seems to make a difference, desirable or not.
>>
>>  >>> import numpy
>>  >>> numpy.__version__
>> '1.0.4.dev3982'
>>  >>> A = numpy.array([1, 2, 3, 4, 5, 6, 5, 4, 5, 4, 3, 2, 1])
>>  >>> (x, y) = numpy.histogram(A, range(0, 7))
>>  >>> x
>> array([0, 2, 2, 2, 3, 3, 1])
>>  >>> y
>> [0, 1, 2, 3, 4, 5, 6]
>>  >>>
>>  >>> (x, y) = numpy.histogram(A, range=(0, 7))
>>  >>> x
>> array([0, 2, 2, 0, 2, 3, 0, 3, 1, 0])
>>  >>> y
>> array([ 0. ,  0.7,  1.4,  2.1,  2.8,  3.5,  4.2,  4.9,  5.6,  6.3])
> 
> Please check the signature of numpy.histogram(). The two aren't intended to be
> the same. The range argument has nothing to do with the builtin range() function.
> 
>>  >>>
>>  >>>
>>  >>> (x, y) = numpy.histogram(A, range(7,0))
>>  >>> x
>> array([], dtype=int32)
>>  >>> y
>> []
>>  >>>
>>
>> Note that in the last case, the histogram function isn't returning 
>> anything for a descending range.
>>
>> Also notice that you're overwriting a python function with the way 
>> you're assigning things....
> 
> No, he's not. "range" is a keyword argument to histogram(). He's using it correctly.
> 



More information about the NumPy-Discussion mailing list