Setting array values ​​in -inf in Python using scipy / numpy

I have an array that looks like this:

a = [ -22  347 4448  294  835 4439  587  326]

I want to set 0 or less values ​​to -inf. I tried the following:

a[where(a <= 0)] = -inf

when I do this, I get an error message:

OverflowError: cannot convert float infinity to integer

Any idea why this is the case and how I can fix it? the where function should return indexes of values ​​less than or equal to 0, and assignment should simply set these values ​​to -inf. thank.

+3
source share
2 answers

Your array ais an array of integers. Integers cannot represent infinity - only floating point numbers. So there are fixes:

  • .

  • , . -2147483648, 32- . , , -infinity, .

,

a[a <= 0] = <somevalue>
+10

, -infinity. IEEE. .

+2

Source: https://habr.com/ru/post/1778205/


All Articles