返回的数组意外

时间:2019-03-15 18:45:05

标签: julia

以下几行

s = [1 2 5 7 3 3]
index=findall(x -> (x < 7 & x > 3), s)
[idx[2] for idx in index]

返回

0-element Array{Int64,1}

s中有5。怎么了?

2 个答案:

答案 0 :(得分:3)

private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e) { var cellInfo = dataGrid.SelectedCells[0]; var content = (cellInfo.Column.GetCellContent(cellInfo.Item) as TextBlock).Text; var r = new Regex("[M][0-9]{6}"); if (r.IsMatch(content.ToString())) { MainWindow frm = new MainWindow(); frm.tabControl.SelectedIndex = 4; } } 是按位AND运算符,运算符优先级在此处插入。 Julia中的逻辑AND运算符为&

您可以使用括号使表达式正确无误,即&&,尽管我不建议这样做。

您应该改用逻辑AND运算符(x > 7) & (x > 3),或者最好直接写在纸上的内容,即&&。所有这些方法都有效。

3 < x < 7

答案 1 :(得分:3)

&对位和逻辑进行运算,并且为&&

对于您要执行的操作,只需使用过滤器即可:

julia> filter(x -> 7 > x > 3, s)
1-element Array{Int64,1}:
 5
相关问题