1

I am trying to make an array in logscale with python 3 and numpy.

I have an issue with the boudaries of my array, the returned array give a lower limit below the limit I want.

For instance :

In : a = np.array(379/19)
In : x = np.geomspace(a, 20)
In : x[0] >= a
Out: False

Whereas with linspace it works :

In : y = np.linspace(a, 20)
In : y[0] >= a
Out: True

Is it an known issue with logspace and geomspace ?

Thanks for your help !

Louis
  • 43
  • 5
  • Thanks to Warren Weckesser answer in a previous post, to ensure that my array have the right boudary I can use : `x[0] = a`, but I am wondering if there is a cleaner answer to this issue. – Louis May 23 '17 at 16:04
  • Possible duplicate of [Python : Geomspace (np.logspace like) does not respect boudaries](https://stackoverflow.com/questions/44136851/python-geomspace-np-logspace-like-does-not-respect-boudaries) – endolith Jun 24 '17 at 03:59
  • close this version as a duplicate of the other, since that has more details and comments – endolith Jun 24 '17 at 04:00

1 Answers1

1

You're essentially testing floats for equality, which is a bad idea.

a    is 19.94736842105263
x[0] is 19.947368421052627
y[0] is 19.94736842105263

So they are very close, but not identical. This is how floating-point math typically works, and you can't generally guarantee whether one will be greater or less than the other, due to rounding error.

What are you trying to do with these boundaries, exactly?

endolith
  • 25,479
  • 34
  • 128
  • 192