回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我使用的是python3.6和numpy。在</p>
<p>从hdf5文件中,我读取了一个2D数组的表列。在</p>
<p>数组的每一行保存有限元节点的ID。在</p>
<p>该表的结构使得它在同一个表中同时包含低阶和高阶元素(这很糟糕,但不是我可以更改的自由度)</p>
<p>所以数组看起来像这样(除了它可能有数百万行)</p>
<pre><code>[[1,2,3,4,0,0,0,0], #<- 4 Node quad data packed with zeros
[3,4,5,6,0,0,0,0],
[7,8,9,10,11,12,13,14], #<- 8 node quad in the same table as 4 node quad
[15,16,17,18,19,20,21,22]]
</code></pre>
<p>我需要将这些信息分成两个独立的数组-一个用于4节点,一个用于8节点行。在</p>
^{pr2}$
<p>现在我在2D数组上迭代,检查每行中第5个值的值,并创建两个索引数组——一个标识4个节点行,另一个标识8节点行。在</p>
<pre><code>for element in elements:
if element[5] == 0:
tet4indices.<a href="https://www.cnpython.com/list/append" class="inner-link">append</a>(index)
else:
tet10indices.append(index)
index+=1
</code></pre>
<p>然后我使用索引数组切片来获得这两个数组</p>
<pre><code>tet4s=elements[tet4indices, 0:5]
tet10s=elements[tet10indices,0:10]
</code></pre>
<p>上面的方法可行,但看起来有点难看。在</p>
<p>如果有人有更好的解决方案,我会很高兴听到。。。。。在</p>
<p>提前谢谢你</p>
<p>道格</p>