Index Array without Elements

后端 未结 3 1087
温柔的废话
温柔的废话 2021-01-17 23:28

I have a vector

a = Vector(1:4)

[1, 2, 3, 4]

and I want to index it to all elements but the third to get

[1,         


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-17 23:45

    This use case is a common one and is covered by the InvertedIndices.jl package. If you install it then you can run:

    julia> using InvertedIndices
    
    julia> a = 1:4
    1:4
    
    julia> a[Not(3)]
    3-element Array{Int64,1}:
     1
     2
     4
    

    Also some packages (like DataFrames.jl) automatically load this package (so if you e.g. use DataFrames.jl you do not have to install and load InvertedIndices.jl separately).

提交回复
热议问题