0

I am using numpy.logspace(-4,1,6) to create [0.0001, 0.001, 0.01, 0.1, 1, 10].

I noticed the numbers generated with numpy.logspace have numeric errors.

print('{:.24f}'.format(np.logspace(-4, 1, 6)[3]))

prints "0.100000000000000005551115" versus "0.1" i expected.

Anyways to eliminate numpy.logspace numeric errors for integer powers of 10 (i.e., 10^n, where n is integer)?

Thanks.

Berk
  • 1
  • 2
    This has nothing to do with numpy at all; there simply is no floating-point number with a value of exactly 0.1. – jasonharper Jun 18 '17 at 22:21

1 Answers1

0

The simple answer is: no.

The somewhat longer answer is, that no floating point number with the value 0.1 exists, at least not "exact" (well, it's exact, i.e. within machine precision, for the computer but not in an analytical/mathematical sense)

Check out: https://en.wikipedia.org/wiki/Floating-point_arithmetic for further info.

rammelmueller
  • 1,092
  • 1
  • 14
  • 29