Is there a faster way to find the position of certain elements (referred to as target below) from a list (referred to as myList below)?
In my case, myList is a large list with around 200,000 sublists, each containing approximately 10 elements.
The 'target' list consists of around 400,000 elements.
I ran the code Map[First, Position[myList, #]] & /@ target, but it was very slow, and I estimate it would take more than 500 hours to complete.
I checked the PositionIndex function, but it doesn't work in this case. Below is the example code using much smaller data.
myList = {{{1, 2, 3, 4, 5, 6, 7, 8}, {9, 10, 11, 12, 13, 14, 15, 16}, {17, 18, 19, 20, 21, 22, 23, 24}, {25, 26, 27, 28, 29, 30, 31, 32}, {33, 34, 35, 36, 37, 38, 39, 40}, {41, 42, 43, 44, 45, 46, 47, 48}, {49, 50, 51, 52, 53, 54, 55, 56}, {57, 58, 59, 60, 61, 62, 63, 64}, {65, 66, 67, 68, 69, 70, 71, 72}, {73, 74, 75, 76, 77, 78, 79, 80}}, {{1, 2, 3, 4, 5, 6, 7, 8}, {9, 10, 11, 12, 13, 14, 15, 16}, {17, 18, 19, 20, 21, 22, 23, 24}, {25, 26, 27, 28, 29, 30, 31, 32}, {33, 34, 35, 36, 37, 38, 39, 40}, {41, 42, 43, 44, 45, 46, 47, 48}, {49, 50, 51, 52, 53, 54, 55, 56}, {57, 58, 59, 60, 61, 62, 63, 64}, {65, 66, 67, 68, 69, 70, 71, 72}, {73, 74, 75, 76, 77, 78, 79, 80}}, {{1, 2, 3, 4, 5, 6, 7, 8}, {9, 10, 11, 12, 13, 14, 15, 16}, {17, 18, 19, 20, 21, 22, 23, 24}, {25, 26, 27, 28, 29, 30, 31, 32}, {33, 34, 35, 36, 37, 38, 39, 40}, {41, 42, 43, 44, 45, 46, 47, 48}, {49, 50, 51, 52, 53, 54, 55, 56}, {57, 58, 59, 60, 61, 62, 63, 64}, {65, 66, 67, 68, 69, 70, 71, 72}, {73, 74, 75, 76, 77, 78, 79, 80}}}; target = {1, 5, 8, 9, 23, 58}; Map[First, Position[myList, #]] & /@ target
Compile[{{myList,_Integer,3}, {target, _Integer, 1}},Map[First, Position[myList, #]] & /@ target][myList,target]I also triedFunctionCompile, but could not get it to work. Looks likeFuncionCompileis still quit restricted, unfortunately. $\endgroup${{1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}, {1, 2, 3}}?? $\endgroup$Block[{c = Merge[MapIndexed[AssociationThread[Catenate[#1] -> First[#2]] &, myList], Identity]}, Lookup[c, target] ]$\endgroup$