Reputation: 55
I have 3D numpy array called BNodeVal
. Currently its size is (1,1,16)
, but it can be bigger than this. I am trying to evaluate an if
condition using this 3D array and 3 coordinates coord_x , coord_y, coord_z
.
BNodeVal = [[[ 0. 1. 15. 0. 0. 13.4 1.77 15.9
1.77 37.391 1.03 40.931 39.161 0.5402 0. 0. ]]]
Below is that portion of the code that is not working correctly:
for j in range(int(np.amax(BNodeval[i, :, 1]))):
print("x = ", coord_x, "\ny =", coord_y, "\nz =", coord_z)
print("3 = ", BNodeval[i][j][2], "\n4 =", BNodeval[i][j][3], "\n5 =", BNodeval[i][j][4])
print(np.isclose(coord_x, BNodeval[i][j][2]))
print(np.isclose(coord_y, BNodeval[i][j][3]))
print(np.isclose(coord_z, BNodeval[i][j][4]))
if np.isclose(coord_x, BNodeval[i][j][2]) and \
np.isclose(coord_y, BNodeval[i][j][3]) and \
np.isclose(coord_x, BNodeval[i][j][4]) : # 1 - 1
print("# 1 - 1")
else:
print('# 1 - 2")
This is what it is printing :
x = 15.0
y = 0.0
z = 0.0
3 = 15.0
4 = 0.0
5 = 0.0
True
True
True
# 1 - 2
However, if i only use one of the np.isclose
terms, it just work fine and print # 1 - 2
instead. Any suggestion is appreciated.
Upvotes: 0
Views: 62
Reputation: 21625
The last test is wrong. You are printing:
print(np.isclose(coord_z, BNodeval[i][j][4]))
But testing:
np.isclose(coord_x, BNodeval[i][j][4])
^ should be z
Upvotes: 1