Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
I have an array: A =MAKE_ARRAY(4000, 120, 60, 3, /FLOAT, VALUE =!VALUES.F_NaN) It consists of numbers between 0 and 1 as well as NaN values. I want to make a binary array from this, such that when an element is NaN, it'll be 0 in the binary array, and when it is a number between 0 and 1, it'll be 1 in the binary array. Perhaps there is a quick solution which I have not found yet? Thanks in advance, Oliver
On Monday, November 18, 2013 8:51:09 AM UTC+1, Oliver Angelil wrote: > I have an array: > > > > A =MAKE_ARRAY(4000, 120, 60, 3, /FLOAT, VALUE =!VALUES.F_NaN) > > > > It consists of numbers between 0 and 1 as well as NaN values. I want to make a binary array from this, such that when an element is NaN, it'll be 0 in the binary array, and when it is a number between 0 and 1, it'll be 1 in the binary array. > > > > Perhaps there is a quick solution which I have not found yet? > > > > Thanks in advance, > > > > Oliver Hi Oliver, how about using the FINITE() function (http://www.exelisvis.com/docs/FINITE.html). IDL> PRINT, FINITE(ALOG(FINDGEN(10)-5.0)) 0 0 0 0 0 0 1 1 1 1 IDL> help, FINITE(ALOG(FINDGEN(10)-5.0)) <Expression> BYTE = Array[10] IDL> PRINT, ALOG(FINDGEN(10)-5.0) -NaN -NaN -NaN -NaN -NaN -Inf 0.000000 0.693147 1.09861 1.38629 You might then use WHERE to locate the NaN or finite value accordingly. So, in your case I would use something like this (free to modify): B = BYTARR(4000, 120, 60, 3) FiniteVals = WHERE(FINITE(A), Count) IF Count GT 0 THEN B[FiniteVals] = 1B Finite will find both NaNs and Inf. Use the appropriate keywords of Finite if you wish to select only one of the two. Hope it helps. Regards, Helder
Le lundi 18 novembre 2013 08:51:09 UTC+1, Oliver Angelil a écrit : > I have an array: > > > > A =MAKE_ARRAY(4000, 120, 60, 3, /FLOAT, VALUE =!VALUES.F_NaN) > > > > It consists of numbers between 0 and 1 as well as NaN values. I want to make a binary array from this, such that when an element is NaN, it'll be 0 in the binary array, and when it is a number between 0 and 1, it'll be 1 in the binary array. > > > > Perhaps there is a quick solution which I have not found yet? > > > > Thanks in advance, > > > > Oliver This is the purpose of the FINITE function. From IDL documentation: "Returns 1 (True) if its argument is finite. If the argument is infinite or not a defined number (NaN), the FINITE function returns 0 (False). The result is a byte expression of the same structure as the argument X." Then, you can simply write: IDL> A =MAKE_ARRAY(4000, 120, 60, 3, /FLOAT, VALUE =!VALUES.F_NaN) ... populate A ... IDL> B = Finite(A) use B ... alx.
B = Finite(A) is what I wanted. Wow, that was extremely easy. Thanks a lot you two! Oliver On Monday, 18 November 2013 09:57:53 UTC+1, alx wrote: > Le lundi 18 novembre 2013 08:51:09 UTC+1, Oliver Angelil a écrit : > >> I have an array: > >> > >> > >> > >> A =MAKE_ARRAY(4000, 120, 60, 3, /FLOAT, VALUE =!VALUES.F_NaN) > >> > >> > >> > >> It consists of numbers between 0 and 1 as well as NaN values. I want to make a binary array from this, such that when an element is NaN, it'll be 0 in the binary array, and when it is a number between 0 and 1, it'll be 1 in the binary array. > >> > >> > >> > >> Perhaps there is a quick solution which I have not found yet? > >> > >> > >> > >> Thanks in advance, > >> > >> > >> > >> Oliver > > > > This is the purpose of the FINITE function. From IDL documentation: > > > > "Returns 1 (True) if its argument is finite. If the argument is infinite or not a defined number (NaN), the FINITE function returns 0 (False). The result is a byte expression of the same structure as the argument X." > > > > Then, you can simply write: > > IDL> A =MAKE_ARRAY(4000, 120, 60, 3, /FLOAT, VALUE =!VALUES.F_NaN) > > ... populate A ... > > IDL> B = Finite(A) > > use B ... > > > > alx.