From a rank 3 matrix like
M =
{
{{a, v, x01}, {a, w, x02}, {a, x, x03}, {a, y, x04}, {a, z, x05}},
{{b, v, x06}, {b, w, x07}, {b, x, x08}, {b, y, x09}, {b, z, x10}},
{{c, v, x11}, {c, w, x12}, {c, x, x13}, {c, y, x14}, {c, z, x15}},
{{d, v, x16}, {d, w, x17}, {d, x, x18}, {d, y, x19}, {d, z, x20}}
};
I want to extract information based , for instance, on the following keys :
Keys1 = {y, w};
Keys2 = {d, a, b};
Using
Map[Cases[Flatten[Map[Cases[Flatten[P, 1], {_, #, _}] &, Keys1], 1], {#, _, _}]&,Keys2]
gives the desired unsorted result:
{{{d, y, x19}, {d, w, x17}}, {{a, y, x04}, {a, w, x02}}, {{b, y, x09}, {b, w, x07}}}
In reality, my matrices have up to 30000 rows, but always 3 columns: Key1 (String), Key2 (String), x01 ... x20 (Lists of real values)
Because of many repetitive lookups, timing here is important, so my question is:
Are there faster ways?
Thanks in advance for your help
Dispatch
and friends. I think browsing this site for that function will result with many topics related to your question. There are also answers based on different constructions. $\endgroup$30000
matrix. Is that too long? $\endgroup$