Extracting indices using findall()

Hello all,

I am trying to extract indices and assign it to a variable, my simple code is as follows

ind1 = Vector{Int64}(undef, 4)

L = [0, 0, 0, 0]
z = [0,1,1,1]
ind1 = map(1:4) do i
    findall(x->x==L, z)
end

The answer should be: ind1 = [1] as at only index one we have z = L. But it isnt working, can anyone help me out here?

Thanks

The simplest is:

ind1 = findall(L .== z)

Alternatively:

ind1 = findall(1:4) do i
    L[i] == z[i]
end

Thanks, it works but i have to put two conditions for findall, i have modified the code a bit as


M = 1*Matrix(I, 4, 4)
N = M
ind1 = intersect(findall((1:4) do i
    l[i] == z[i]),findall(sum(M[i,j]*z[j] for j in items)+sum(N[i,j]*w[j] for j in items)+q[i]>0),)
end

But this doesnt work, i have to put two conditions actually like this, ind1 should containt the indices where z[i] == L[i] and (Mz + Nw + q)_i >0. Any idea how can i tackle it?

ind1 = indall(1:4) do i
    MzNwq = sum(M[i,j]*z[j] for j in items)+sum(N[i,j]*w[j] for j in items)+q[i]
    l[i] == z[i] && MzNwq > 0
end

however you normally calculate (Mz + Nw + q)_i

1 Like

Works perfect. Thank you so much :slight_smile: