I am trying to determine boundary node indices in a 2D domain using the following python code,
import numpy as np
...
b_index0 = np.where( (nodeDat[:,2] == xu) or
(nodeDat[:,2] == xl) or
(nodeDat[:,3] == yu) or
(nodeDat[:,3] == yl) )
where nodeDate[:,2] and nodeDat[:3] are lists of floating point x and y values respectively.
This produces the following error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
I tried a number of variations using np.add() and np.all(), but none seemed to work.
If I use | instead of or, I get the following error:
ValueError: could not broadcast input array from shape (200) into shape (1)
By experimentation, I found that the following code generates a correct list of 200 indices, which is the answer I require :
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)))
However, this seems to be an inefficient/inelegant way of achieving the desired result. It also produces duplicate indices, hence the call to np.unique().
The following suggested link provides some background as to why the initial code does not work, but does not appear to provide a solution to my particular problem. stackoverflow answer