Dalek
Dalek

Reputation: 4318

How could I make logarithmic bins between 0 and 1?

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?

Upvotes: 1

Views: 2755

Answers (2)

albialbi
albialbi

Reputation: 11

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])

Upvotes: 1

Ricardo Cárdenes
Ricardo Cárdenes

Reputation: 9172

How about:

np.logspace(0.0, 1.0, nstep) / 10.

Upvotes: 2

Related Questions