Skip to content Skip to sidebar Skip to footer

Grouping Of A List's Values Into Equal Distance Bins

I have a list: long_list = [] for i in range(100): long_list.append(i) I'm trying to create a function that takes that list, and a number of bins, and outputs a new list where

Solution 1:

My first thought is a combination of numpy.linspace (https://numpy.org/doc/stable/reference/generated/numpy.linspace.html) and numpy.digitize (https://numpy.org/doc/stable/reference/generated/numpy.digitize.html). You can get the bin edges using np.linspace(), then use those bin edges in np.digitize(), which will return the bin indices for the given values.


Post a Comment for "Grouping Of A List's Values Into Equal Distance Bins"