Re: what dose a(a<3)=0 mean, where a is a one dimensional array?

From: Dave Allured <dave.allured_at_nyahnyahspammersnyahnyah>
Date: Tue Mar 20 2012 - 22:23:57 MDT

Perhaps Dr. Chuliang wants the .lt. operator, not the < operator.
They mean two very different things; see "Expressions" in the NCL
users manual.

> a=(/1,2,3,2,1,2,1,2,4,3,1,2/)
> a(ind(a.lt.3))=0
> print (a)

(0) 0
(1) 0
(2) 3
(3) 0
(4) 0
(5) 0
(6) 0
(7) 0
(8) 4
(9) 3
(10) 0
(11) 0

--Dave

On Tue, Mar 20, 2012 at 9:55 PM, Dennis Shea <shea@ucar.edu> wrote:
> Variable 'a' is type integer.
>
> If you try
> ncl > a=(/1,2,3,2,1,2,1,2,4,3,1,2/)
> ncl > print(a<3)
>                   ; all integers
> (0)     1
> (1)     2
> (2)     3
> (3)     2
> (4)     1
> (5)     2
> (6)     1
> (7)     2
> (8)     3
> (9)     3
> (10)    1
> (11)    2
>
> ncl > a(a<3)=0
>
> Takes the a<3 integers and uses them as subscripts
> and sets them to zero.
>
> --
> It only works for integers. Try
>
> ncl > b=(/1,2,3,2,1,2,1,2,4,3,1,2/)*1.0
> ncl > q= b<3
> ncl > print(q)
>
> Variable: q
> Type: float       <*************
> Total Size: 48 bytes
>             12 values
> Number of Dimensions: 1
> Dimensions and sizes:   [12]
> Coordinates:
> (0)      1
> (1)      2
> (2)      3
> (3)      2
> (4)      1
> (5)      2
> (6)      1
> (7)      2
> (8)      3
> (9)      3
> (10)     1
> (11)     2
>
> ncl > print(b(b<3))
>
> or
>
> ncl > print(b(q))
>
> fatal:Illegal subscript. Vector subscripts must be integer
>
>
> On 3/20/12 9:41 PM, Chuliang Xiao wrote:
>> Dear NCL users,
>> some confusion about the following codes
>>  >a=(/1,2,3,2,1,2,1,2,4,3,1,2/)
>>  >a(a<3)=0
>>  >print(a)
>> (0) 1
>> (1) 0
>> (2) 0
>> (3) 0
>> (4) 1
>> (5) 2
>> (6) 1
>> (7) 2
>> (8) 4
>> (9) 3
>> (10) 1
>> (11) 2
>> Best regards
>> ------------------------------------------------------------------------
>> Dr. Chuliang XIAO(肖楚良)
>> School of Atmospheric Sciences,
>> Nanjing University,
>> No. 22 Hankou Road, Nanjing 210093, China
>> Tel: +86-138-0514 5653
>> Email: xiaocl@smail.nju.edu.cn <mailto:xiaocl@smail.nju.edu.cn>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Tue Mar 20 22:24:07 2012

This archive was generated by hypermail 2.1.8 : Tue Mar 27 2012 - 08:50:24 MDT