Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using numpy.logspace() : how to generate numbers spaced evenly on a log-scale

Tags:

python

numpy

I am trying to use numpy.logspace()to generate 50 values from 1e-10 to 1e-14.

http://docs.scipy.org/doc/numpy/reference/generated/numpy.logspace.html

import numpy as np
x = np.logspace(1e-10, 1e-14, num=50)
print x

The output I get is incorrect:

[ 1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.
  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.
  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.  1.]

What are my other options?

like image 837
ShanZhengYang Avatar asked Jul 02 '15 18:07

ShanZhengYang


People also ask

What is the difference between Linspace and Logspace?

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

What is NumPy Linspace?

The NumPy linspace function (sometimes called np. linspace) is a tool in Python for creating numeric sequences. It's somewhat similar to the NumPy arange function, in that it creates sequences of evenly spaced numbers structured as a NumPy array.


1 Answers

>>> import numpy as np
>>> np.logspace(-10, -14, 50)
array([  1.00000000e-10,   8.28642773e-11,   6.86648845e-11,
         5.68986603e-11,   4.71486636e-11,   3.90693994e-11,
         3.23745754e-11,   2.68269580e-11,   2.22299648e-11,
         1.84206997e-11,   1.52641797e-11,   1.26485522e-11,
         1.04811313e-11,   8.68511374e-12,   7.19685673e-12,
         5.96362332e-12,   4.94171336e-12,   4.09491506e-12,
         3.39322177e-12,   2.81176870e-12,   2.32995181e-12,
         1.93069773e-12,   1.59985872e-12,   1.32571137e-12,
         1.09854114e-12,   9.10298178e-13,   7.54312006e-13,
         6.25055193e-13,   5.17947468e-13,   4.29193426e-13,
         3.55648031e-13,   2.94705170e-13,   2.44205309e-13,
         2.02358965e-13,   1.67683294e-13,   1.38949549e-13,
         1.15139540e-13,   9.54095476e-14,   7.90604321e-14,
         6.55128557e-14,   5.42867544e-14,   4.49843267e-14,
         3.72759372e-14,   3.08884360e-14,   2.55954792e-14,
         2.12095089e-14,   1.75751062e-14,   1.45634848e-14,
         1.20679264e-14,   1.00000000e-14])
like image 158
Curt F. Avatar answered Nov 04 '22 16:11

Curt F.