Setting values of an array to -inf in Python with scipy/numpy -
i have array looks this:
a = [ -22 347 4448 294 835 4439 587 326] i want set 0 or smaller values -inf. tried following:
a[where(a <= 0)] = -inf when this, error:
overflowerror: cannot convert float infinity integer any idea why , how can fix it? "where" function should return indices of values less or equal 0, , assignment should set values -inf. thanks.
your array a array of integers. integers can't represent infinity -- floating point numbers can. there fixes:
use array of floating point numbers instead.
use large negative integer value, e.g.
-2147483648if using 32-bit integers. of course that's not same -infinity, in contexts behaves similar.
furthermore, can write
a[a <= 0] = <somevalue>
Comments
Post a Comment