empty 'where(...,/null)' and compound operators

38 views
Skip to first unread message

markus.sc...@gmail.com

unread,
May 13, 2025, 9:15:35 AMMay 13
to idl-pvwave
Is the following behavior deliberate or a bug?
IDL> seed=1LL
IDL> for i=0,2000 do begin rn=randomn(seed,10) & rn[where(rn lt 0,/null)]*= -1
% Variable is undefined: <UNDEFINED>.
% Execution halted at: $MAIN$          
IDL> a=findgen(10)
IDL> a[!null] *= -1
% Variable is undefined: <UNDEFINED>.
% Execution halted at: $MAIN$ 

alx

unread,
May 13, 2025, 10:10:29 AMMay 13
to idl-pvwave
IDL> a = findgen(10)
IDL> help, a[!null]
IDL> <Expression>    UNDEFINED = !NULL
seems  consistent to me, since:     a[!null] *= -1   is equivalent to a[!null] = a[!null]*(-1)

markus.sc...@gmail.com

unread,
May 13, 2025, 10:45:48 AMMay 13
to idl-pvwave
yes, I know, but in NumPy it conveniently doesn't fail:
import numpy as np                                                                                                                                                                                                                                                    
x=np.arange(10)                                                                                                                                                                                                                                                       
x[x < 0] *= -1
x[np.zeros(10).astype(np.bool)] *= -1
Reply all
Reply to author
Forward
0 new messages