I’m new to APL. How can I remove unwanted elements from an array?
For example:
X←1 2 3 4 5 6 7 8 9
Now I want to remove elements of X that equal either 4 or 6. I tried
X←4↓X
to drop 4 from X, but it didn’t work. Thanks in advance.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this, assuming x = 1 2 3 4 5 6 7 8 9
Explaination
Find 4 and 6 in the array
xwithx∊4 6which outputs:
0 0 0 1 0 1 0 0 0(the locations of 4 and 6)Now, Negate this array with
~which outputs1 1 1 0 1 0 1 1 1(the opposite of the above)Apply this to the array x with
/xwhich leaves you with1 2 3 5 7 8 9Finally, assign this to x with
x←leaving x with your desired output.