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

To list the occurrence of values in the numpy array following your code you could change it to:

Numpy is much more powerful than a way to loop over the values of a raster. You probably should do some serious reading (NumPy — Numpy) . Maybe an expert on numpy (Dan Patterson) has some suggestions for you.