Hi guys, this is my first time posting so please forgive mistakes.
I am a python newbie, and I have a census tract shapefile joined to income category data. I want to calculate an entropy value, which follows this formula:
A*Ln(1/A)+B*Ln(1/B)+C*Ln(1/C) etc.
where A, B, C, etc are proportions of the population of each tract within each income category.
Some values are 0, and they break the formula because it divides by zero as you can see in the formula.
I want to automate this formula so that the user of the tool simply has to input the census data.
I have thought about making a cursor that loops through a conditional statement like this:
for row in rows:
if row >= 0:
return True
else:
return False
then, I want to put all the ones that returned True into the formula and omit the false ones.
I have thought about creating extra columns for every original value so each new column contains a "A*Ln(1/A)" component, and then sum only those that are not NULL, but I do not know how to make python do this. Ideas? There must be a way.