I have an array a=rand(100)
, I want to get every value except the values at the indices notidx=[2;50]
. Is there a clean way to get a
a
If you are using julia-v0.5+, you can also use the new generator expression, for example:
view(a, [i for i in indices(a)... if i ∉ notidx])
and
[a[i] for i in indices(a)... if i ∉ notidx]
To get a copy, you can firstly make a copy of a
, then manipulate it with deleteat!
to delete those values at specific indices. After you've done this, it's convenient to get a view of a
via indexin
:
a = rand(100)
# => 100-element Array{Float64,1}:
0.62636
0.488919
0.499884
....
b = copy(a)
deleteat!(b, [2,50])
# => 98-element Array{Float64,1}:
0.62636
0.499884
....
I don't have anything super clean, but you can do
a[setdiff(1:end, notidx)]
which is slightly cleaner than what you had, or
ind = trues(length(a))
ind[notidx] = false
a[ind]
which is pretty verbose but very clear.