3

I am getting a TypeError like this for the following code.

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

    import numpy as np
    import matplotlib.pyplot as plt
    import math

    plt.axis([1,5000,100,10**20])
    plt.xscale('log')
    plt.yscale('log')
    plt.savefig('test.png')
    plt.close()

When I set the maximum value for y-axis as 10^19, there is no error. But from 10^20, I start getting the TypeError described above.

Could you help me understand this error and set the y-axis range from 1 to 10^20?

flaton
  • 43
  • 4
  • 4
    I found that the error doesn't occur if instead of `10**20` you write `1.e20`. Also I found that that the range of 64bit-integers is of order `10**18`: `float(2**63)` gives `9.223372036854776e+18`. I can't explain this way why you start to experience problems from `10**20` on, except one assumes that because of the log-scaled axes unsigned integers are used. Then the max range is of order `10**19` and larger numbers might cause problems. Then again the order of the commands does not speak for that argumentation. – Michael H. Mar 20 '17 at 09:15
  • 4
    Notice that the error comes from the NumPy function `np.isfinite`. `np.isfinite(10**19)` gives `True` while `np.isfinite(10**20)` gives that error. Even though Python can handle arbitrarly large integers, NumPy is written in C and works with standard data types like 64bit integers. – Michael H. Mar 20 '17 at 09:17
  • 2
    `type(10**10)` will get you ``, while `type(1e20)` returns ``. And although [there's no limit](http://stackoverflow.com/questions/9860588/maximum-value-for-long-integer) on how large a long can be, somewhere inside the power calculation there must be some limitation. Try with floats as suggested by @Michael. – berna1111 Mar 20 '17 at 11:35

0 Answers0