为什么当我尝试锻炼1条件的1功能,但当我试图添加下一步-它只给黑色光栅?
而不是平均> 0.05*99 -我试着做:(平均>0.05*99 ) &(平均< 0.20*99) (这是条件:大于5%,但小于20% )。
Python规则编写多个条件可能有问题吗?
def computeThirdCondition(myArray):
print "Executing Third Condition:"
#Set up empty array:
myArrayThird = numpy.zeros(myArray.shape).astype(float)
thirdCondition = (theInputArray==11)|(theInputArray==12)*1
for i in range (1,numpy.size(myArray,1)-1):
for j in range (1,numpy.size(myArray,0)-1):
average = 0.0
for ii in range(i-6,i+7):
for jj in range(j-4,j+5):
average = average + thirdCondition[j][i]
if (average > 0.05*99)&(average < 0.20*99):
myArrayThird[j][i] = 1
return myArrayThird发布于 2016-03-18 04:45:08
在Python中,&是按位的and运算符,而逻辑and只是and。将您的行从
if (average > 0.05*99)&(average < 0.20*99): 至:
if average > 0.05 * 99 and average < 0.20 * 99:甚至:
if 0.20 * 99 > average > 0.05 * 99:https://stackoverflow.com/questions/36076241
复制相似问题