Page 1 of 1

Array selection & selective assignment

PostPosted: January 15th, 2012, 8:50 am
by Ajay Askoolum
given an array of rank 2 or above, I'd like to be able to do

1. return the elements where the condition is true as a vector e.g.

array[array >10]

2. selectively reassign those elements

array[array >10] <- 0

I know that both are achievable with a slight rearrangement of the syntax but what I propose is an intuitive extension.

PostPosted: January 16th, 2012, 8:47 pm
by aplus
How about simply doing this:

Code: Select all
     Å’„A„5 5½¼25
  1  2  3  4  5
  6  7  8  9 10
 11 12 13 14 15
 16 17 18 19 20
 21 22 23 24 25
      ((,A)[((,A)>15)/¼½,A])„0
      A
  1  2  3  4  5
  6  7  8  9 10
 11 12 13 14 15
  0  0  0  0  0
  0  0  0  0  0

PostPosted: January 17th, 2012, 5:09 am
by Ajay Askoolum
I think I did mention that I know the alternative syntax & proposed the implementation as it is simpler (to me, more intuitive).
But, thanks for the suggestion.