Subset array conditional on boolean

You could also do the following:

data = [ X Y ]
data0 = data[ S , : ]
data1 = data[ .!S, : ]

This first copies your X and Y into a data matrix.
Then you use the logical indexing ( S ) for the first index and : for the second index, meaning take all.

This introduces a little more copying of data but as long as your code is not performance critical, it shouldn’t be a problem.

2 Likes