0

I have defined a function to loop over the range of 10^-9 to 10^3 for every 10^3 steps.

 import math

   a = 2 
   b = 2 
   def f(L): 
      f = ab/L 

  for i in range(10**-9, 10**3, 10**3): 
       print (f(i)) 

I get following error with this code:

TypeError: range() integer step argument expected, got float.
MartyIX
  • 27,828
  • 29
  • 136
  • 207
Darshi
  • 33
  • 1
  • 5
  • And what don't you understand about the error message? – jonrsharpe Mar 14 '16 at 22:41
  • @jonrsharpe I don't think he's confused by the error message. His topic line contains the question: what is the correct way of doing this? – Kurt Stutsman Mar 14 '16 at 22:42
  • You should look into the numpy module – Mark Skelton Mar 14 '16 at 22:44
  • I want to know a way to obtain this range without typing it out [10**-9, 10**-8, 10**-7, 10**-6, 10**-5, 10**-4, 10**-3, 10**-2, 10**-1,1, 10**1, 10**2, 10**3]. I tried np.arange() still not luck. – Darshi Mar 14 '16 at 23:19
  • np.logspace(-9, 3, 11) woks. – Darshi Mar 15 '16 at 00:16
  • `np.logspace(-9, 3, 11)` is neither equivalent to your original code (which will only give [1e-9] using `np.arange`), nor [10**-9, 10**-8, 10**-7, 10**-6, 10**-5, 10**-4, 10**-3, 10**-2, 10**-1,1, 101[sic], 102[sic], 10**3]. For the latter, you'd want `np.logspace(9,3,13)`. Also, use `1e-9` instead of `10**-9`. – Jan Christoph Terasa Mar 15 '16 at 06:38

0 Answers0