I would like to know if it is possible to select all but one element (by index) in a julia array.
For example in R language in order to not select a particular row i
Here is one option:
A = rand(3,3)
B = A[1:end .!= 2,:]
1:end
gets a complete list of row indices (you could also use 1:size(A,1)
) and then .!=
(note the .
indicating element-wise comparison) selects the indices not equal to 2.
If you wanted to select columns in this way you would use:
C = A[:, 1:end .!= 2]
Note that the end
keyword automatically will equal the last index value of the row, column, or other dimension you are referencing.
Note: answer updated to reflect improvements (using end
instead of size()
) suggested by @Matt B in comments.