I am trying to insert a value for different group of percentile eg (0- 10 percentitle) value = 1.
I saw an example over here and went to try it out How do I Calculate Grouped Percentiles or Batch percentiles in ArcMap?
However, i was thrown this error. I am using ArcGis 10.3.1 for desktop. and the file is Shapefile Feature Class.
Runtime error
Traceback (most recent call last):
File "<string>", line 30, in <module>
File "<string>", line 10, in CalcPercentile
File "C:\Python27\ArcGIS10.3\lib\site-packages\numpy\lib\function_base.py", line 3096, in percentile
return _compute_qth_percentile(sorted, q, axis, out)
File "C:\Python27\ArcGIS10.3\lib\site-packages\numpy\lib\function_base.py", line 3132, in _compute_qth_percentile
return add.reduce(sorted[indexer]*weights, axis=axis, out=out)/sumval
TypeError: unsupported operand type(s) for *: 'numpy.ndarray' and 'numpy.ndarray'
The source code is over here. (using python)
import arcpy
import numpy as np
import os
#loop through all Shapefile in a folder and call the CalcPercentile method
def CalcPercentile(inputFeatureClass):
#to create 3 rank for example
print inputFeatureClass;
arr = arcpy.da.FeatureClassToNumPyArray(inputFeatureClass, 'NEAR_DIST_')
p1 = np.percentile(arr, 33) # rank = 0
p2 = np.percentile(arr, 67) # rank = 1
p3 = np.percentile(arr, 100) # rank = 2
#use cursor to update the new rank field
with arcpy.da.UpdateCursor(inputFeatureClass , ['NEAR_DIST_','PerRank1']) as cursor:
for row in cursor:
if row[0] < p1:
row[1] = 0 #rank 0
elif p1 <= row[0] and row[0] < p2:
row[1] = 1
else:
row[1] = 2
cursor.updateRow(row)
workspace = "D:\HDB_accessibility\MergeAllDistance"
walk = arcpy.da.Walk(workspace, datatype="FeatureClass")
for dirpath, dirnames, filenames in walk:
for filename in filenames:
featureClass = os.path.join(dirpath, filename)
#First add the percentile Rank Field
#arcpy.AddField_management(featureClass, "PerRank", "DOUBLE")
CalcPercentile(featureClass)
Best Answer
As commented by @fluidmotion it: