How to find a list of elements in an array using python -
How to find a list of elements in an array using python -
i have 2 sets of info both have values refer part of larger set of info (points in unstructured mesh).
the 2 smaller sets of info contain vectors have global id references point in larger set of data. like:
large set of data:
0 0 0 0 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 1 smaller sets of data:
a
0 1 3 5 4 5 6 7 7 2 b
0 10 4 12 7 60 the first column in smaller sets of info reference line number in larger set of data. sec column in smaller set of info illustration data.
it worth mentioning first column of b subset of first column of a.
what need row indices of point ids match in b.
in case be:
ind = [0,2,4] i.e. a[ind,0] = b[:,0]
i have managed using loop, datasets increasing in size on 10 1000000 , loop far slow. can suggest faster methods?
putting first column info of b set should speed things up. assuming , b lists of tuples (or lists), seek this:
>>> [('0', '1'), ('3', '5'), ('4', '5'), ('6', '7'), ('7', '2')] >>> b [('0', '10'), ('4', '12'), ('7', '60')] >>> bkeys=set([i[0] in b]) >>> [i i,v in enumerate(a) if v[0] in bkeys] [0, 2, 4] python
Comments
Post a Comment