次の python コードを使用して、2D ドメインの境界ノード インデックスを決定しようとしています。
import numpy as np
...
b_index0 = np.where( (nodeDat[:,2] == xu) or
(nodeDat[:,2] == xl) or
(nodeDat[:,3] == yu) or
(nodeDat[:,3] == yl) )
ここでnodeDate[:,2]
、 とnodeDat[:3]
は、それぞれ浮動小数点x
とy
値のリストです。これにより、次のエラーが発生します。
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
np.add() と np.all() を使用していくつかのバリエーションを試しましたが、どれもうまくいかないようでした。
|
の代わりに使用するとor
、次のエラーが発生します。
ValueError: could not broadcast input array from shape (200) into shape (1)
実験により、次のコードが 200 個のインデックスの正しいリストを生成することがわかりました。これが私が必要とする答えです。
b_index00 = np.where(nodeDat[:,2] == xu)
b_index01 = np.where(nodeDat[:,2] == xl)
b_index02 = np.where(nodeDat[:,3] == yu)
b_index03 = np.where(nodeDat[:,3] == yl)
b_index0 = np.unique(np.hstack((b_index00, b_index01,b_index02, b_index03)))
ただし、これは目的の結果を達成するための非効率的/非効率的な方法のようです。また、重複するインデックスも生成するため、np.unique()
.
次の推奨リンクは、最初のコードが機能しない理由についての背景を提供しますが、特定の問題の解決策を提供しているようには見えません。 スタックオーバーフローの答え