如何索引除选择索引之外的所有索引? [英] How to index all but select indices?
本文介绍了如何索引除选择索引之外的所有索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
at the other values? I am looking for a good way to do both a copy and a view.
Currently I make the array [1;3:49;51:100]
by symdiff(1:100,notidx)
, but a[symdiff(1:length(a),notidx)]
and view(a,a[symdiff(1:length(a),notidx)])
are not very clean (or understandable to others) ways of doing this.
解决方案
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.
这篇关于如何索引除选择索引之外的所有索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文