How could I make logarithmic bins between 0 and 1?

Question:

I want to bin my data logarithmically while they are distributed between zero and one. I use this command :

nstep=10
loglvl=np.logspace(np.log10(0.0),np.log10(1.0),nstep)

but it doesn’t work. any idea how it can be done in python?

Asked By: Dalek

||

Answers:

How about:

np.logspace(0.0, 1.0, nstep) / 10.
Answered By: Ricardo Cárdenes

The idea is to choose a low "second number", then compute logarithmic-spaced values from this number to 1.0, and finally add zero at the beginning.

For example, setting 1.0e-8 as the second number in our sequence:

nstep = 10
seq = np.logspace(-8.0, 0.0, nstep)
np.insert(seq, 0, 0.0)

Which produces:

array([0.00000000e+00, 1.00000000e-08, 7.74263683e-08, 5.99484250e-07,
   4.64158883e-06, 3.59381366e-05, 2.78255940e-04, 2.15443469e-03,
   1.66810054e-02, 1.29154967e-01, 1.00000000e+00])
Answered By: albialbi
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.