numpy not-equally distant range of numbers

Viewed 59

Using np.linspace(0,3,100) would give a range of numbers that are equally distant between 0 and 3. what's the best way to get a range of numbers between 0 and 3 but more densely close to 3 and less dense in the beginning, perhaps in a logarithmic way.

----------edit

(np.log10(1), np.log10(4), 100)-1 gives more dense samples close to 0 than 3.

In addition is there also a more mathematically explicit way?

------edit:

This is the best I myself could come up with: s = -1*(3*10**(-np.linspace(0,4,25))-1)

2 Answers

Try np.logspace(). You will need to use np.log10() for arguments.

A slight improvement over np.logspace is np.geomspace, which is more convenient since endpoints can be specified directly. rpoleski's answer then becomes

4 - np.geomspace(1, 4, 25)[::-1]
Related