I have a vector of 3d coordinates which needs to be checked for upper vale in a grid of 3d coordinates
#vector
vec=[(.033,-.22,.98),(.5,-.9,.0029),(-.77,-.01,-.092),(.5,.2,.0029)]
#grid
x1 = np.linspace(-1,1,10)
y1 = np.linspace(-1,1,10)
z1 = np.linspace(-1,1,10)
Im using this code which is clearly wrong, because its just comparing the first x coordinate only and not the rest of y,z
ctr=0
for v in vec:
for i in x1:
for j in y1:
for k in z1:
if ctr==0:
temp=(i,j,k)
ctr+=1
continue
else:
#print temp, "to" ,i,j
temp2=(i,j,k)
if temp<=v<=temp2:
print "low,high",temp, temp2
temp=(i,j,k)
ctr+=1
===WRONG OUTPUT======
low,high (-0.052631578947368474, 1.0, 1.0) (0.052631578947368363, -1.0, -1.0)
low,high (0.47368421052631571, 1.0, 1.0) (0.57894736842105265, -1.0, -1.0)
low,high (-0.78947368421052633, 1.0, 1.0) (-0.68421052631578949, -1.0, -1.0)
low,high (0.47368421052631571, 1.0, 1.0) (0.57894736842105265, -1.0, -1.0)
Ive pasted a 2d grid here (3d will follow the same logic). So we start iterating the grid from cell (0,0) in a serial order. As you can see the lower & higher coordinate for point v