擅长:python、mysql、java
<p>在数组中,很容易找到第5个元素为0或不是0的行:</p>
<pre><code>In [75]: arr = np.array(alist)
In [76]: arr
Out[76]:
array([[ 1, 2, 3, 4, 0, 0, 0, 0],
[ 3, 4, 5, 6, 0, 0, 0, 0],
[ 7, 8, 9, 10, 11, 12, 13, 14],
[15, 16, 17, 18, 19, 20, 21, 22]])
In [77]: arr[:,5]
Out[77]: array([ 0, 0, 12, 20])
In [78]: eights = np.where(arr[:,5])[0]
In [79]: eights
Out[79]: array([2, 3], dtype=int32)
In [80]: arr[eights,:]
Out[80]:
array([[ 7, 8, 9, 10, 11, 12, 13, 14],
[15, 16, 17, 18, 19, 20, 21, 22]])
In [81]: fours = np.where(arr[:,5]==0)[0]
In [82]: arr[fours,:]
Out[82]:
array([[1, 2, 3, 4, 0, 0, 0, 0],
[3, 4, 5, 6, 0, 0, 0, 0]])
</code></pre>
<p>或者使用布尔掩码</p>
^{pr2}$
<p>从某种意义上说,你很幸运拥有这个清晰的<code>0</code>标记。一些有限元代码重复节点数以减少节点数,例如[1,2,3,3]对于4节点系统中的3节点单元。但在这些情况下,其余的数学工作正常,即使你将两个节点合并为一个。在</p>