Finding sub-arrays in an array?

I’m putting this here because this is a chemistry usage but it’s not really a chemistry-specific case.

I have an array that has a bunch of states formatted like this:

1.0 1.0 0.0 1.0 0.0 1.0 6380.35
1.0 1.0 1.0 1.0 0.0 1.0 6316.91
2.0 1.0 1.0 2.0 0.0 2.0 6444.27
2.0 1.0 2.0 1.0 0.0 1.0 11086.5

For any given line, 1:3 is a description of one state, 4:6 is the description of a second state, and 7 is the frequency of the difference.

I have created a list of all the states (which is all the values 1:3 and 4:6 listed in an nx3 array) and of all the unique states, and I need to identify which states only appear once in the list. However,

findall(isequal(unst[1,:]), states[1:3,:])

Is not working – it provides an empty Cartesian index

CartesianIndex{2}

Preferably, I would be able to find the index of every unique state in the overall nx7 list. Does anyone know how to do this?

Thanks!

The issue is that isequal operates on the entire array, rather than columnwise like you seem to want. SInce the entire matrix does not match unst[1,:], you get a single false as a result.

Does

findall(isequal(unst[1,:]), eachcol(@view(states[1:3, :]))) # @view is optional

do what you want? This should slice the matrix into each 3-tall column and compare each of those to unst[1, :].

For example,

julia> findall(isequal([1;2;3]), eachcol([1;1;1;; 1;2;3;; 3;2;1;; 2;2;2;;]))
1-element Vector{Int64}:
 2
1 Like