a=[[1],[1,2],[2,1],[2,5],[111,3],[4,1]]
6-element Vector{Vector{Int64}}:
[1]
[1, 2]
[2, 1]
[2, 5]
[111, 3]
[4, 1]
I want to get the index which of them contain a element named 1,but 111 is not allowed.I want to return [1,2,3,6] .If the sub-vector contains real 1 ,I will return the index. What should I do ? Thanks very much.
findall?
I do not know how you want to approach this as a
is a vector of vectors.
Though something like this does work:
findall.(x -> x == 1, a)
JorizovdZ:
findall.(x -> x == 1, a)
findall.(x -> x == 1, a)
6-element Vector{Vector{Int64}}:
[1]
[1]
[2]
[1]
[]
[2]
Sorry, It cannot return the index. like [1,2,3,6]
1 Like
lmiq
October 3, 2022, 12:02pm
4
julia> findall(x -> 1 in x, a)
4-element Vector{Int64}:
1
2
3
6
4 Likes
DNF
October 3, 2022, 12:02pm
5
zhangchunyong:
a=[[1],[1,2],[2,1],[2,5],[111,3],[4,1]]
julia> findall(1 in v for v in a)
4-element Vector{Int64}:
1
2
3
6
3 Likes
An alternative:
LinearIndices(a)[in.(1, a)]