comp.lang.idl-pvwave archive - RDF feed
type: channel
description: Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado
items: Array into binary array
items: Re: Array into binary array

Array into binary array
type: item
description: 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
creator: Oliver Angelil
date: 2013-11-18T07:51:09-00:00

Re: Array into binary array
type: item
description: 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
creator: Helder Marchetto
date: 2013-11-18T08:18:19-00:00

Re: Array into binary array
type: item
description: 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.
creator: lecacheux.alain
date: 2013-11-18T08:57:53-00:00

Re: Array into binary array
type: item
description: 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.
creator: Oliver Angelil
date: 2013-11-18T09:08:52-00:00