<div dir="ltr"><span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:16px">Hi Nick,</span><div><span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:16px">This might work:</span></div><div><span style="color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif;font-size:16px">riskvalues_st = tostring(where(riskvalues.gt.1,1,0))</span><div><span style="font-size:16px;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif">riskwords = where(riskvalues_st.eq."1","High",riskwords) ; assigns a high risk when precipitation is large</span></div></div><div><span style="font-size:16px;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif">If that doesn't work or if you have any further questions let ncl-talk know.</span></div><div><span style="font-size:16px;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif">Adam</span></div><div><span style="font-size:16px;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif"><br></span></div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jun 22, 2018 at 9:34 AM Bassill, Nicholas <<a href="mailto:nbassill@albany.edu">nbassill@albany.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div id="m_-7169429113384083017divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Hi All,</p>
<p style="margin-top:0;margin-bottom:0"> This isn't an important question, but it's an issue that's cropped up for me enough to count on two hands now. Basically, I'd love to use the "where" function to return values that are not of the same type as the conditional
expression. I'm just wondering if anyone has an elegant way around this that doesn't involve a do loop and if check. </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">This often gives an error, as the documentation notes ("<span style="color:rgb(51,51,51);font-family:verdana,sans-serif;font-size:13.3333px">If neither type can be coerced to the other type, an error is returned</span>"). </p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Here's a standard example of why I'd like to use it this way. Say I'm making a risk table for various weather phenomena contingent on that phenomena's value (like say, wind speed or rainfall).</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">It'd be really nice/easy to be able to do something like:</p>
<p style="margin-top:0;margin-bottom:0">----------------</p>
<p style="margin-top:0;margin-bottom:0">; note: below two arrays have same size</p>
<p style="margin-top:0;margin-bottom:0">riskvalues = *series of random numbers for a variable, say precipitation in inches*</p>
<p style="margin-top:0;margin-bottom:0">riskwords = *series of words - begin with all equal to "None"*</p>
<p style="margin-top:0;margin-bottom:0">riskwords = where(riskvalues.gt.1,"High",<span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">riskwords)
; assigns a high risk when precipitation is large</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">--------------</span></p>
<p style="margin-top:0;margin-bottom:0"><span style="font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols;font-size:16px">This will give
an error because you're returning a string, which can't be coerced to the number type you're evaluating. </span></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">So my question is twofold - (1) is there a way/flag to negate this behavior? and (2) assuming not, does anyone have a more elegant solution than a nested assignment inside an if check inside a do loop? It seems like the
point of where is to avoid this situation.</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Thanks for any input!</p>
<p style="margin-top:0;margin-bottom:0"> - lazy coder</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<div id="m_-7169429113384083017Signature">
<div id="m_-7169429113384083017divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div id="m_-7169429113384083017divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<p><span style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px">Nick Bassill, PhD</span></p>
<p style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px">
Modeler & Meteorologist, Center Of Excellence (Prior: NYS Mesonet)</p>
<p style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px">
LC SB-28, 1400 Washington Ave.,</p>
<p style="color:rgb(0,0,0);font-family:Calibri,Arial,Helvetica,sans-serif;font-size:16px">
SUNY, University at Albany, NY 12222</p>
(518) 442-6375</div>
<div id="m_-7169429113384083017divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Calibri,Arial,Helvetica,sans-serif,Helvetica,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
NYSM Products: <a href="http://operations.nysmesonet.org/~nbassill/" class="m_-7169429113384083017OWAAutoLink" id="m_-7169429113384083017LPNoLP" target="_blank">http://operations.nysmesonet.org/~nbassill/</a></div>
</div>
</div>
</div>
</div>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div><div><span><font color="#888888">Adam Phillips <br></font></span></div><span><font color="#888888">Associate Scientist, </font></span><span><font color="#888888">Climate and Global Dynamics Laboratory, NCAR<br></font></span></div></div><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli/" target="_blank">www.cgd.ucar.edu/staff/asphilli/</a> </font></span><span><font color="#888888">303-497-1726 </font></span></div><span><font color="#888888"></font></span><div><div><span><font color="#888888"><br></font></span><div><span><font color="#888888"><a href="http://www.cgd.ucar.edu/staff/asphilli" target="_blank"></a></font></span></div></div></div></div></div></div></div></div></div></div></div>