Hi all,
What’s the best way to separate elements of a vector based on the value of the last member?
All = [ (15,12,875), (25,132, 333), (7,9, 201), (147,92, 201), (77,59, 333), (15,11,875), (10,12,875), (4,12,875), (25,132,875), (25,132, 31), (7,9, 333), (154,92, 201), (36,55, 31), (125,18,875), (10,12,33)]
What I need is a systematic way to first find all elements with the same last index and then put them into a collection of vectors. For the above example this would be:
Separated = [
[(15,12,875), (15,11,875), (10,12,875), (4,12,875), (25,132,875), (125,18,875) ],
[ (25,132, 333), (77,59, 333), (7,9, 333) ].
[ (7,9, 201), (147,92, 201), (154,92, 201) ],
[ (25,132, 31), (36,55, 31)],
[(10,12,33)]
]
Here’s my try: first find all last elemnts then?
All = [ (15,12,875), (25,132, 333), (7,9, 201), (147,92, 201), (77,59, 333), (15,11,875), (10,12,875), (4,12,875), (25,132,875), (25,132, 31), (7,9, 333), (154,92, 201), (36,55, 31), (125,18,875), (10,12,33)]
u1 = zeros(length(All))
for i in eachindex(All)
u1[i] = All[i][3]
end
u2 =unique(u1)
for i in u2
#find the elements and put them into an array