[ncl-talk] index lists in assignment

Rick Brownrigg brownrig at ucar.edu
Fri Nov 30 11:26:29 MST 2018


Hi Axel,

Apologies in delay in getting back to you on this.  As far as I can tell,
the behavior ox "x(idx) = x(idx) + z" is the intended behavior (perhaps not
the same as "desired" behavior in your case), in the sense that the
right-hand side is completely evaluated before the (re)assignment to the
variable "x": is performed.

The do-loop approach does work -- it it just unbearably slow?  Without
knowing more about your data, I don't have a suggestion for how to avoid
looping.

Rick


On Thu, Nov 29, 2018 at 10:37 AM Axel Seifert <Axel.Seifert at dwd.de> wrote:

>
> Maybe I should add that the output of my little script is
>
>
> (0)      0 0
> (1)      3 4
> (2)      2 2
>
>
> This is with NCAR Command Language Version 6.3.0
>
>
> The variables x and y are
>
>
> Variable: x
> Type: float
> Total Size: 12 bytes
>             3 values
> Number of Dimensions: 1
> Dimensions and sizes:   [3]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue :  9.96921e+36
> (0)      0
> (1)      3
> (2)      2
>
> Variable: y
> Type: float
> Total Size: 12 bytes
>             3 values
> Number of Dimensions: 1
> Dimensions and sizes:   [3]
> Coordinates:
> Number Of Attributes: 1
>   _FillValue :  9.96921e+36
> (0)      0
> (1)      4
> (2)      2
>
>
>
> Am 24.11.2018 um 15:16 schrieb Seifert Axel:
>
>
> Hi,
>
>
> I have a somewhat unexpected behavior when using index lists. Here a
> simplified example:
>
>   x = new( 3, float)
>   x = 0.0
>   y = x
>
>   z = (/1.,2.,3./)
>   idx = (/1,2,1/)
>
>   x(idx) = x(idx) + z
>
>   do i=0,dimsizes(idx)-1
>     y(idx(i)) = y(idx(i)) + z(i)
>   end do
>
>   print(" "+x+" "+y)
>
> I would have expected that x and y end up being the same, but they are
> not. The double assignment to index 1 does not work for the vector
> assignment. Is this the intended behavior for arrays in ncl?
>
> How can I get the 2nd behavior and still avoid the do-loop?
>
> In my case I am assigning measured values from satellite overpasses to a
> global grid and it can of course happen that I have multiple overpasses for
> a grid point in an observation vector. Hence, in addition to the sum of the
> values I would count the number of overpasses
>
>   cnt = (/0,0,0/)
>   cnt(idx) = cnt(idx) + 1
>   print(" "+cnt)
>
> and then xavg = x/cnt should give me the proper average for, for example,
> one hour of data. What I need in the end is the correct average for xavg
> and the number of measurements used at each grid point.
>
> Thanks in advance for any helpful comments and suggestions.
>
> Axel
>
>
>
>
>
>
>
> _______________________________________________
> ncl-talk mailing listncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20181130/3efcff37/attachment.html>


More information about the ncl-talk mailing list