首页 > 解决方案 > Julia: How to obtain all but one point from an array?

问题描述

Say x = [1:5..] and I wish to return an array with the element 1:2 and 4:5 i.e. all but one element namely 3. How do I do that?

I tried x[1:2; 4:end] and x[1:2 4:end]. Neither worked.

I would really like to use the end keyword if possible.

标签: julia

解决方案


InvertedIndices.jl有一个很好的接口:

julia> using InvertedIndices

julia> v = map(i -> i => rand(), 1:5)
5-element Array{Pair{Int64,Float64},1}:
 1 => 0.8165266824627073
 2 => 0.38840874144349025
 3 => 0.061178225310028145
 4 => 0.6615139442678073
 5 => 0.10733363621427094

julia> v[Not(3)]
4-element Array{Pair{Int64,Float64},1}:
 1 => 0.8165266824627073
 2 => 0.38840874144349025
 4 => 0.6615139442678073
 5 => 0.10733363621427094

推荐阅读