Arrays Julia-滤波阵列的多重条件

Arrays Julia-滤波阵列的多重条件,arrays,filter,julia,Arrays,Filter,Julia,给定如下数组: 5-element Array{String,1}: "Computer science" "Artificial intelligence" "Machine learning" "Algorithm" "Mathematics" 在Julia中,如何通过多个条件过滤它?例如,我想获得所有 不是计算机科学或人工智能的价值观,因此,我想获得: 3-element Arr

给定如下数组:

5-element Array{String,1}:
 "Computer science"
 "Artificial intelligence"
 "Machine learning"
 "Algorithm"
 "Mathematics"
在Julia中,如何通过多个条件过滤它?例如,我想获得所有 不是计算机科学或人工智能的价值观,因此,我想获得:

3-element Array{String,1}:
 "Machine learning"
 "Algorithm"
 "Mathematics"

也许是这样的

julia> x = ["Computer science", "Artificial intelligence", "Machine learning", "Algorithm", "Mathematics"]
5-element Array{String,1}:
 "Computer science"
 "Artificial intelligence"
 "Machine learning"
 "Algorithm"
 "Mathematics"

# Note the double parentheses, in order to build the
# ("Computer science", "Artificial intelligence") tuple
#
# It would also be possible (but probably less efficient) to put
# those values in a vector
julia> filter(!in(("Computer science", "Artificial intelligence")), x)
3-element Array{String,1}:
 "Machine learning"
 "Algorithm"
 "Mathematics"
编辑:如注释中所述,如果要过滤掉的值列表较长,则构建一个集合而不是元组可能更有效:


应该注意的是,如果用于过滤的值列表长于几个元素,则应将它们放入具有Olnn搜索时间的集合中,而不是元组或向量的集合中。简而言之,建议的方法将是最快的。好主意@PrzemyslawSzufel!我编辑了我的答案以反映您的评论,谢谢!
julia> filter(!in(Set(("Computer science", "Artificial intelligence"))), x)
3-element Array{String,1}:
 "Machine learning"
 "Algorithm"
 "Mathematics"