Hi Guillermo,

You can do that indeed, that's just Perl. If you wanted to do operations on a 
subset of that ndarray, then you'd do e.g.

$pdl->where(($pdl-0.5)->abs < 0.2) *= 5;

An observation is that the above condition could be a bit shorter by using the 
recently-added approx_artol: (which would also mean it ran quicker)

$pdl->approx_artol(0.5, 0.2)

Best regards,
Ed

________________________________
From: Guillermo P. Ortiz <gor...@exa.unne.edu.ar>
Sent: 20 January 2025 19:39
To: pdl-devel@lists.sourceforge.net <pdl-devel@lists.sourceforge.net>; perldl 
<pdl-gene...@lists.sourceforge.net>
Subject: [Pdl-devel] conditional inline

Hello !

I am not sure, but maybe It is possible to do with perl PDL something
like this?

$ndarray= condition on $ndarray ? assign when true : assign when false

for example:

$x=zeroes(20)->xlinvals(0,1);

$y=(all abs($x-0.5)<0.2)?$x**2:$x;

Thanks in advance

Regards

--


Dr. Guillermo P. Ortiz
Electromagnetismo Aplicado
Dto. FĂ­sica, Facultad de Ciencias Exactas
Universidad Nacional del Nordeste
Avda Libertad 5460, Campus UNNE.
W3404AAS Corrientes, Argentina.
(+54) 379-4424678 interno 4613
gortiz at unne edu ar
_______________________________________________
pdl-devel mailing list
pdl-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pdl-devel

Reply via email to