'invalid value encountered in double_scalars' warning, possibly numpy

前端 未结 7 1045
一向
一向 2020-12-03 09:34

As I run my code I get these warnings, always in groups of four, sporadically. I have tried to locate the source by placing debug messages before and after certain statement

相关标签:
7条回答
  • 2020-12-03 10:01

    In my case, I found out it was division by zero.

    0 讨论(0)
  • 2020-12-03 10:01

    Sometimes NaNs or null values in data will generate this error with Numpy. If you are ingesting data from say, a CSV file or something like that, and then operating on the data using numpy arrays, the problem could have originated with your data ingest. You could try feeding your code a small set of data with known values, and see if you get the same result.

    0 讨论(0)
  • 2020-12-03 10:02

    I encount this while I was calculating np.var(np.array([])). np.var will divide size of the array which is zero in this case.

    0 讨论(0)
  • 2020-12-03 10:14

    It looks like a floating-point calculation error. Check the numpy.seterr function to get more information about where it happens.

    0 讨论(0)
  • 2020-12-03 10:15

    Whenever you are working with csv imports, try to use df.dropna() to avoid all such warnings or errors.

    0 讨论(0)
  • 2020-12-03 10:16

    Zero-size array passed to numpy.mean raises this warning (as indicated in several comments).

    For some other candidates:

    • median also raises this warning on zero-sized array.

    other candidates do not raise this warning:

    • min,argmin both raise ValueError on empty array
    • randn takes *arg; using randn(*[]) returns a single random number
    • std,var return nan on an empty array
    0 讨论(0)
提交回复
热议问题