I am currently working on a high-performance python 2.7 project that lists tens of thousands of elements. Obviously, each operation should be performed as quickly as possible.
So, I have two lists: one of them is a list of unique arbitrary numbers, let it be called A, and the other is a linear list starting with 1 and with the same length as the first list, with the name B, which represents the indices in (starting from 1)
Something like an enumeration starting at 1.
For example:
A = [500, 300, 400, 200, 100]
B = [ 1, 2, 3, 4, 5]
If I have an element B (called e_B) and the corresponding element in A is required, I can just do correspond_e_A = A[e_B - 1]. No problems.
But now I have a huge list of random, not unique integers, and I want to know the indices of the integers that are in A, and what are the corresponding elements in B.
I think I have a reasonable solution for the first question:
indices_of_existing = numpy.nonzero(numpy.in1d(random_list, A))[0]
What's good about this approach is that there is no need to match () single operations, numpy in1d just returns a list, for example [True, True, False, True, ...]. Using nonzero (), I can get the indexes of the elements in random_list that exist in A. Ideally, I think.
But for the second question, I'm at a standstill. I tried something like:
corresponding_e_B = map(lambda x: numpy.where(A==x)[0][0] + 1, random_list))
, , (), -, , , , numpy.where() , (, A ), , , .
bisect, , bisect , , , map() ( , ? )
Python, , - ? , , ?