Search code examples
pythonnumpygeometrycomputational-geometrylogarithm

"backwards" np.geomspace so a higher density occurs as log function gets higher


I need to generate numbers in a logarithmic space from .5 to 1.

This code accomplishes that:

IN: np.geomspace(.5, 1, num=10) OUT: [0.5, 0.540029869446153, 0.5832645197880583, 0.6299605249474366, 0.6803950000871885, 0.7348672461377994, 0.7937005259840997, 0.8572439828530728, 0.9258747122872905, 1.0]

However, the smaller increments occur closer to .5. I'd like them to occur closer to 1 (hence, backwards, I'm just not entirely sure what the right term would be).

I've tried np.geomspace(1, .5, num=10) but it just gives me the same output in reverse order.


Solution

  • IIUC you can do:

    import numpy as np
    
    1.5 - np.geomspace(1, .5, num=10)
    array([0.5       , 0.57412529, 0.64275602, 0.70629947, 0.76513275,
           0.819605  , 0.87003948, 0.91673548, 0.95997013, 1.        ])