How to put data into bins using NumPy in Python

Putting data into bins using NumPy groups similar data points. For example, with the dataset [0.1, 4, 5, 6] and bins as 0.0 to 1.0 and 1.0 to 7.0, [0.1] goes in the 0.0 to 1.0 bin and [4, 5, 6] goes in the 1.0 to 7.0 bin.

Solution for How to put data into bins using NumPy in Python : You can use numpy.digitize() to put data into binsCall numpy.digitize(x, bins) with x as a NumPy array and bins as a list containing the start and end point of each bin. Each element of the resulting array is the bin number of its corresponding element in the original array.


how-to-put-data-into-bins-using-numpy-in-python