Use of 'in' or function in array

Example array:
C = [1 2 3 5;4 5 6 8;7 8 9 0; 3 6 9 12]
4×4 Array{Int64,2}:
1 2 3 5
4 5 6 8
7 8 9 0
3 6 9 1

I could strip out cols, or rows by

C[1:end .!=2,1:end .!=3]
3×3 Array{Int64,2}:
 1  2   5
 7  8   0
 3  6  1

But, I would expect to use in like:

C[1:end .in([2 3]),1:end .in([1 3])]

You can do

C[in.(1:end, Ref([2, 3])), in.(1:end, Ref([1, 3]))]

, or even better, if [2, 3] and [1, 3] are large arrays:

C[in.(1:end, Ref(Set([2, 3]))), in.(1:end, Ref(Set([1, 3])))]
2 Likes

@simeonschaub Thanks very much.
Your suggestion works,

I’m was looking a way to strip out row or cols which has sum of rows or cols in some condition.
then I use eachrow and eachcol to get these rows/cols conditions.
With your suggestions I could create a very nice function.
After I learn more about Julia, I will try to make a generic function to strip out rows/cols for arrays.

2 Likes