我正在将numexpr模块用于python。 我正在尝试运行下一个代码段:
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${com.querydsl.version}</version>
<classifier>jpa</classifier>
</dependency>
但是import numexpr as ne
def main():
result = ne.evaluate('where((1 > 9) & (where(1 > 9, 9, 1) == 0), 2, 3)')
print(f'Result: {result}')
if __name__ == "__main__":
main()
会引发以下错误:
numexpr
但是,如果我在单独的表达式中提取冲突的部分,那么它会起作用。
TypeError: unsupported operand type(s) for &: 'bool' and 'ConstantNode'
但是想法是有一个表达式。 有谁知道我该如何重写此公式才能使其正常工作?
谢谢。
答案 0 :(得分:1)
pop = (((0,4,0,4),10),((4,8,4,8),30))#original raster with two pixels, store as the Vertex coordinates ((xmin,xmax,ymin,ymax),pixel value)
min_r_x = []
min_r_y = []
max_r_x = []
max_r_y = []
pop_r = []
x1 = []
x2 = []
y1 = []
y2 = []
#loc = []
pop_r = []
area = 4*4
#re = 4
newre = 2
#max_y = 4
#min_x = 0
val = []
#get the vertex coordinates of new raster
for row in range(2):
for col in range(4):
min_r_x = 0 + col*newre
max_r_x = 0 + (col+1)*newre
max_r_y = 4 + row*(-newre)
min_r_y = 4 + (row+1)*(-newre)
pop_r.append(((min_r_x,max_r_x,max_r_y,min_r_y),0))
#take each of the new raster vertex cooordinates locate their position
for i in range(len(pop_r)):
pairs = pop_r[i]
coor = pairs[0]
#val = pairs[1]
coorxmin = coor[0]
coorxmax = coor[1]
coorymax = coor[2]
coorymin = coor[3]#loop each vertex of pixels
for j in range(len(pop)):
record = pop[j]
loc = record[0]
xmin = loc[0]
xmax = loc[1]
ymin = loc[2]
ymax = loc[3]
#here is the place that I have some problem, it seems not right
if xmin <= coorxmin <= xmax:
x1.append(xmax-coorxmin)
val.append(record[1])
if xmin <= coorxmax <= xmax:
x2.append(xmax - coorxmax)
val.append(record[1])
if ymin <= coorymin <= ymax:
y1.append(ymax-coorymin)
val.append(record[1])
if ymin <= coorymax <= ymax:
y2.append(ymax-coorymax)
val.append(record[1])
value = (x1 * y1 * val + x1*y2*val + x2*y1*val + x2*y2*val)/area
pop_r.append(((min_r_x[i],max_r_x[i],min_r_y[i],max_r_y[i]),value))
是按位的&
运算符。为什么不只使用and
?