Difference in output between numpy linspace and numpy logspace

后端 未结 4 1795
梦毁少年i
梦毁少年i 2021-01-04 04:46

Numpy linspace returns evenly spaced numbers over a specified interval. Numpy logspace return numbers spaced evenly on a log scale.

I don\'t understand why numpy log

4条回答
  •  Happy的楠姐
    2021-01-04 05:17

    logspace computes its start and end points as base**start and base**stop respectively. The base value can be specified, but is 10.0 by default.

    For your example you have a start value of 10**0.02 == 1.047 and a stop value of 10**2 == 100.

    You could use the following parameters (calculated with np.log10) instead:

    >>> np.logspace(np.log10(0.02) , np.log10(2.0) , num=20)
    array([ 0.02      ,  0.0254855 ,  0.03247553,  0.04138276,  0.05273302,
            0.06719637,  0.08562665,  0.1091119 ,  0.13903856,  0.17717336,
            0.22576758,  0.28768998,  0.36659614,  0.46714429,  0.59527029,
            0.75853804,  0.96658605,  1.23169642,  1.56951994,  2.        ])
    

提交回复
热议问题