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:

  1. use array of floating point numbers instead.

  2. use large negative integer value, e.g. -2147483648 if using 32-bit integers. of course that's not same -infinity, in contexts behaves similar.

furthermore, can write

a[a <= 0] = <somevalue> 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -