【发布时间】:2019-02-10 21:15:58
【问题描述】:
我想按元素(或广播)检查向量 x 的元素是否在 Julia 中的向量 y 中,就像函数 checkin 所做的那样:
x = ["one", "two", "three", "four"]
y = ["two", "three", "five", "four"]
function checkin(x,y)
for i = 1:length(y)
if y[i] ∈ x
println(true)
else
println(false)
end
end
end
checkin(x,y)
输出:
true
true
false
true
如果我输入
x .∈ y
或
x .in y
我收到一个错误
通常,我确信存在一种更简单的方法来编写一个 9 行函数,但我找不到它
【问题讨论】:
标签: vector julia element broadcasting