Reputation: 3862
I have two numpy arrays "Elements" and "nodes". My aim is to gather some data of these arrays. I need to remplace "Elements" data of the two last columns by the two coordinates contains in "nodes" array. The two arrays are very huge, i have to automate it.
An example :
import numpy as np
Elements = np.array([[1.,11.,14.],[2.,12.,13.]])
nodes = np.array([[11.,0.,0.],[12.,1.,1.],[13.,2.,2.],[14.,3.,3.]])
results = np.array([[1., 0., 0., 3., 3.],
[2., 1., 1., 2., 2.]])
On a last post Stack', someone helps me to do it :
e = Elements[:,1:].ravel().astype(int)
n=nodes[:,0].astype(int)
I, J = np.where(e==n[:,None])
results = np.zeros((e.shape[0],2),nodes.dtype)
results[J] = nodes[I,1:]
np.concatenate((Elements[:,[0]],results.reshape(2,4)),axis=1)
It works here, but when i do on a great number of values, i got an error : "need more than 1 value to unpack" but i dont understand what is the origin of the problem...
--- EDIT LATER -----
I think it could be due to the importance of my arrays. Perhaps is there an other way to deal with this problem? (21536, 4) and Nodes_coord.shape : (10926, 3)
Upvotes: 0
Views: 101
Reputation: 4706
It looks like you're using at least one element which does not have a corresponding node. Try this code to check if this is indeed the case:
element_ids = Elements[:, 1]
node_ids = nodes[:, 0]
valid = np.all([elem_id in node_ids for elem_id in element_ids ])
I'm guessing valid
will be False
.
Upvotes: 1