Ok, I found a recipe to discretize an array with numpy.
Problem is, np.histogram_bin_edges (and, therefore, np.histogram) and np.digitize are not consistent in how they use bins edges: first 2 always return an extra edge, what ever right mode you use in np.digitize, which always leaves you with one "outlier" category.
What one has to do is (assuming edges appear in ascending order)
bin_edges=np.histogram_bin_edges(arr,bins=4) #or any other source
if bin_edges[0] <= arr.min():
categorized_arr=np.digitize(arr,bins=bin_edges[1:],right=True)
elif bin_edges[-1] >= arr.max():
categorized_arr=np.digitize(arr,bins=bin_edges[:-1],right=False)