0
x = np.linspace(-1,1,10)
for k in x:
    print (Fraction(k).denominator)

I 'm trying to get the denominator for this values in this range, but I get this instead

1
9007199254740992
4503599627370496
9007199254740992
2251799813685248
2251799813685248
4503599627370496
562949953421312
1125899906842624
1
  • Those are in fact the actual denominators of the actual numbers in your array, because floats can only represent rational numbers with power-of-two denominators. If you're doing something where the concept of a denominator is meaningful, you probably shouldn't be using floating-point math in the first place - you should use integer or rational math the whole way. – user2357112 Jan 31 '21 at 23:27
  • inclusive of end points you probably want 11 elements.. Loonk at `x` itself. – hpaulj Feb 01 '21 at 00:54
  • Where are you importing `Fraction` from? – hpaulj Feb 01 '21 at 01:08

0 Answers0