Search code examples
pythonpython-3.xnumpymathhistogram

TypeError: histogram() got an unexpected keyword argument 'normed'


I am using numpy.histogram and I am getting this error:

import numpy as np
np.histogram(np.arange(4), bins=np.arange(5), normed=True)

TypeError: histogram() got an unexpected keyword argument 'normed'

I was expecting:

(array([0.2,0.25,0.25]),array([0,1,2,3,4]))

I am using numpy 1.24.3


Solution

  • The normed parameter in the numpy.histogram function was deprecated in NumPy version 1.21.0 and removed in version 1.24.0.

    Example

    import numpy as np
    
    result = np.histogram(a=np.arange(4), bins=np.arange(5), density=True)
    print(result)
    # (array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4]))