我想检查某个随机序列的第一个数字是否在 -1 < x < 1 范围内,x我想检查的数字在哪里。
举个例子,
A = [-20.665,1.334,0.112,-2.334]
Run Code Online (Sandbox Code Playgroud)
我们如何找到 A[1] 在 -1 < A[1] < 1 中?
简单的。你只要写
if -1 < A[1] < 1
# everything is awesome
else
# something is wrong
end
Run Code Online (Sandbox Code Playgroud)
这是有效的,因为在 Julia 中允许进行链式比较(就像在 Python 中一样)