comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Array into binary array
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Array into binary array [message #86539 is a reply to message #86538] Mon, 18 November 2013 00:18 Go to previous messageGo to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
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
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: reading in from multiple files, performing operations and printing them to multiple output file
Next Topic: How to access properties of multiple plots in a function graphics window?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Nov 28 09:49:43 PST 2025

Total time taken to generate the page: 0.00822 seconds