Want to do some computation on raster

Discussion created by ahsan_phy@hotmail.com on Jan 29, 2015
Latest reply on Jan 30, 2015 by Dan_Patterson

I am want to calculate repetitive values from raster and save it into dict, how can i do it ? i have done some coding but its not working help me to solve the problem. below is my code:

import numpy as np import arcpy from arcpy import env  env.workspace = r"D:Results" rasterlist = arcpy.ListRasters() array = arcpy.RasterToNumPyArray(raster,nodata_to_value=0) array1 = np.reshape(array, (1,np.product(array.shape)))  mydict = {} for i in array1:     if i in mydict:         mydict[i] += 1     else:         mydict[i] = 1 print mydict


Actually i want to implement the following formula:


where g is the number of tied groups and tp is the number of data in the pth group. For example, in the sequence {23, 24, trace, 6, trace, 24, 24, trace, 23} we have g = 3, t{ = 2 for the tied value 23, t2 = 3 for the tied value 24, and r3 = 3 for the three trace values, where as n = 1