for row in rows: validlist = [] if row.A <> 0: validlist.append(row.A) # trying to think of a way to loop this part, drawing a blank if row.B <> 0: validlist.append(row.B) if row.C <> 0: validlist.append(row.C) . . . if row.N <> 0: validlist.append(row.N) result = validlist[0] * Ln(1/validlist[0]) for i in range(1, len(validlist) + 1): result += validlist * Ln(1/validlist)
Two methods, depending on whether you want to skip the calculation altogether if any value is zero, or if you want to calculate any non-zero values, skipping only zeros. If you have a lot of values to calculate, there's probably a better way, but this will work for your example.edit: also, you marked your own post as answered (green check mark). Use that for whoever best answered your question. Other forum members may not read your post, assuming it's been solved. # Method 1 for row in rows: if A == 0 or B == 0 or C == 0: # you may actually want row.A, etc, here, or row[0], row[1]. Second method is if you use arcpy.da continue # this will skip this row in the for loop else: # do your calculations # Method 2 for row in rows: if A == 0 and B != 0 and C != 0: # calculate only B and C elif A != 0 and B != 0 and C == 0: # calculate only A and B elif: # and so on, for as many combinations as you have
# Method 1 for row in rows: if A == 0 or B == 0 or C == 0: # you may actually want row.A, etc, here, or row[0], row[1]. Second method is if you use arcpy.da continue # this will skip this row in the for loop else: # do your calculations # Method 2 for row in rows: if A == 0 and B != 0 and C != 0: # calculate only B and C elif A != 0 and B != 0 and C == 0: # calculate only A and B elif: # and so on, for as many combinations as you have
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.