Hi Eugene,
Just to add an alternative to Rahman's suggestion, another way to do
this which perhaps looks closer to your algorithm is:
use PDL::NiceSlice; # To allow for $x() syntax...
$diff = $e1->zeroes();
$inds = which($e1 == 0 & $e2 != 0);
$diff($inds) .= $e3($inds) - $e2($inds);
(note the .= on the last line). Using at & set is generally not
necessary - use of PDL::NiceSlice is definitely to be recommended and
remember .= when assigning in these situations.
Cheers,
J.
Quoting "Eugene A. Semenko" <[EMAIL PROTECTED]>:
> Hi. I would like to ask about using of piddles. For instance, I
> have 3 arrays
> of the same length: e1, e2 and e3. Now I try to do something like this (just
> algorithm):
> for (i=0; i < nelements(e1); i++) {
> if (e1(i) == 0.0 && e2(i) != 0)
> diff(i) = e3(i) - e2(i);
> print (diff(i));
> }
>
> So, what is a correct way to do similar loop in PDL where $e1, $e2, $e3 and
> $diff are piddles with some data? Should I use at() and set() to get and set
> piddle's elements?
> Thanks in advance. Sorry for my English.
> --
> ---------------------------------------------------------------------------------------
> Eugene A. Semenko
> e-mail: [EMAIL PROTECTED] Special Astrophysical Observatory RAS,
> WWW: http://tiger.sao.ru/ Nizhnij Arkhyz
> phone: +7 87878 46 5 77 Karachai-Chercassian Republic,
> fax: +7 87878 46 5 27 Russia, 369167
> ---------------------------------------------------------------------------------------
>
> _______________________________________________
> Perldl mailing list
> [email protected]
> http://mailman.jach.hawaii.edu/mailman/listinfo/perldl
>
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
_______________________________________________
Perldl mailing list
[email protected]
http://mailman.jach.hawaii.edu/mailman/listinfo/perldl