我有两个numpy数组“Elements”和“nodes”。我的目标是收集这些数组的一些数据。我需要通过“nodes”数组中包含的两个坐标来重新排列最后两列的“Elements”数据。这两个阵列非常庞大,我必须自动化它。
一个例子:
$description = UnitDescription::find()
->where(['id_unit' => $model->id])
->orderBy([
'upvoted - downvoted' => SORT_DESC //Need this line to be fixed
])
->one();
在最后一篇帖子Stack'上,有人帮助我这样做:
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.]])
它可以在这里工作,但是当我对大量值进行操作时,我得到一个错误:“需要超过1个值才能解压”但我不明白问题的根源是什么...
---编辑以后-----
我认为这可能是由于我的阵列的重要性。或许有另一种方法可以解决这个问题? (21536,4)和Nodes_coord.shape:(10926,3)
答案 0 :(得分:1)
您似乎正在使用至少一个没有相应节点的元素。 尝试使用此代码检查是否确实如此:
element_ids = Elements[:, 1]
node_ids = nodes[:, 0]
valid = np.all([elem_id in node_ids for elem_id in element_ids ])
我猜valid
将是False
。