votes up 1

range argument must have one entry per dimension

Package:
numpy
github stars 18118
Exception Class:
ValueError

Raise code

        # bins is an integer
        bins = D*[bins]

    # normalize the range argument
    if range is None:
        range = (None,) * D
    elif len(range) != D:
        raise ValueError('range argument must have one entry per dimension')

    # Create edge arrays
    for i in _range(D):
        if np.ndim(bins[i]) == 0:
            if bins[i] < 1:
                raise ValueError(
                    '`bins[{}]` must be positive, when an integer'.format(i))
😲  Walkingbet is Android app that pays you real bitcoins for a walking. Withdrawable real money bonus is available now, hurry up! 🚶

Ways to fix

votes up 1 votes down

The range argument should be the same shape as the shape of the data and it should also have a value in each dimension.

Code to reproduce the exception:

 import numpy as np
 d = np.linspace(0, 100, 200000).reshape((-1,2))
 np.histogramdd(d, (10000, 10000), range=[ [0, 100]])

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-44-0f3eb828f48b> in <module>()  1 import numpy as np  2 d = np.linspace(0, 100, 200000).reshape((-1,2)) ----> 3 np.histogramdd(d, (10000, 10000), range=[ [0, 100]]) 
<__array_function__ internals> in histogramdd(*args, **kwargs) 
/usr/local/lib/python3.7/dist-packages/numpy/lib/histograms.py in histogramdd(sample, bins, range, normed, weights, density)  1040 range = (None,) * D  1041 elif len(range) != D: -> 1042 raise ValueError('range argument must have one entry per dimension')  1043   1044 # Create edge arrays 
ValueError: range argument must have one entry per dimension

Fixed version of the code:

 import numpy as np
 d = np.linspace(0, 100, 200000).reshape((-1,2))
 np.histogramdd(d, (10000, 10000), range=[[0, 100], [0, 100]])

May 09, 2022 kellemnegasi answer
kellemnegasi 31.6k

Add a possible fix

Please authorize to post fix