julia - 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.
解决方案
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
推荐阅读
- python - 如何确定字节是 utf-8 还是 utf-16
- python - 替换或交换 3 个列表以创建单个列表/数组
- r - 如何在我的热图上分配 9 列特定颜色的独立渐变?
- c# - 如何解决:下载多个电子表格文件时,该进程无法访问文件“**”,因为它正被另一个进程使用
- django - Embed plotly:dash figure inside django template
- javascript - iPhone / iPad - 终止应用程序时未保存 Safari 浏览器 cookie
- node.js - 为什么我的快速路由器中间件没有定义 req.route?
- vue.js - 事件高度,如使用 vue-cal 的谷歌日历
- wpf - StackPanel 水平内容对齐在 dataTemplate 中居中
- php - 如何使用php只显示全名