I want to return a NumPy array of Element IDs with at least one Node being in the interesting Nodes list.
I have:
A list of interesting Nodes,
Interesting_Nodes.
The size is ~300,000 items.A list of sublists which represent Node forming an Element,
Nodes.
The size is ~1,000,000 lists of ~20 values.Nodes[i]contain the 20 Nodes creatingElements[i]. Which is an integer ID.A list of Elements,
Elements. The size is ~1,000,000 items.
Here is an example of these lists.
import numpy as np
Interesting_Nodes=[1,2,10,40,400,1000]
Elements=[1,2,3]
Nodes=[[1,20,25],[30,400,35],[500,501,502]]
In this case the function will return [1,2] because Elements[0] have the Node 1 in the Interesting_Nodes list and Elements[1] contains the Node 400 which is also in the Interesting_Nodes list
I wrote this it seems to work but is very slow. Is there a way to perform this faster?
def recuperation_liste_element_dans_domaine_interet(Interesting_Nodes,Elements,Nodes):
Liste_elements=list([])
for n in Interesting_Nodes:
id=np.where(Nodes==n)
Liste_elements=Liste_elements+list(Elements[id[0]])
nbrListe = list(set(Liste_elements)) # remove all the element duplication
return np.array(nbrListe)
Another way to perform that I think could be: (be still too slow)
def recuperation_liste_element_dans_domaine_interet(Interesting_Nodes,Elements,Nodes):
Liste_elements=[0]*len(Elements)
compteur=0
j=0
for n in Nodes:
if any(i in Interesting_Nodes for i in n):
Liste_elements[compteur]=Elements[j]
compteur=compteur+1
j=j+1
Liste_elements=Liste_elements[:compteur]
return np.array(Liste_elements)