My goal is (1) to identify tracts that are above the 99 percentile of a variable (xvar), (2) to dissolve contiguous tracts by summing a variable (yvar), and (3) to get the coordinates of the centroids (longitude and latitude) of the merged polygons.
At the very first stage for picking the above-99th-percentile tracts, I have got some errors. The following is my current work:
import arcpyimport numpy as npinput = r'D:\7362.shp'myarray = arcpy.da.FeatureClassToNumPyArray(input, ('xvar'))print myarray# Printed output:# [(5.204770523,) (8.6471839055,) (2.1095837756,) ..., (1.4788840302,# (6.24183499,) (3.6710648163,)]p99 = np.percentile(myarray, 99)# use cursor to create the indicator field# Do I have to create the abovep99 field in the first place???with arcpy.da.UpdateCursor(input, ['xvar','abovep99']) as cursor: for row in cursor: if row[0] > p99: row[1] = 1 else: row[1] = 0 cursor.updateRow(row)The error messages in the percentile calculation p99 = np.percentile(myarray, 99) are following:
Traceback (most recent call last):File "", line 1, in p99 = np.percentile(myarray, 99)File "C:\Python27\ArcGIS10.3\lib\site-packages\numpy\lib\function_base.py", line 3096, in percentilereturn _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_percentilereturn add.reduce(sorted[indexer]*weights, axis=axis, out=out)/sumvalTypeError: unsupported operand type(s) for *: 'numpy.ndarray' and 'numpy.ndarray'So, my question is how to fix this problem for the percentile calculation? Plus, would you please provide some help for step (2) and (3)? Thank you very much!
أكثر...
At the very first stage for picking the above-99th-percentile tracts, I have got some errors. The following is my current work:
import arcpyimport numpy as npinput = r'D:\7362.shp'myarray = arcpy.da.FeatureClassToNumPyArray(input, ('xvar'))print myarray# Printed output:# [(5.204770523,) (8.6471839055,) (2.1095837756,) ..., (1.4788840302,# (6.24183499,) (3.6710648163,)]p99 = np.percentile(myarray, 99)# use cursor to create the indicator field# Do I have to create the abovep99 field in the first place???with arcpy.da.UpdateCursor(input, ['xvar','abovep99']) as cursor: for row in cursor: if row[0] > p99: row[1] = 1 else: row[1] = 0 cursor.updateRow(row)The error messages in the percentile calculation p99 = np.percentile(myarray, 99) are following:
Traceback (most recent call last):File "", line 1, in p99 = np.percentile(myarray, 99)File "C:\Python27\ArcGIS10.3\lib\site-packages\numpy\lib\function_base.py", line 3096, in percentilereturn _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_percentilereturn add.reduce(sorted[indexer]*weights, axis=axis, out=out)/sumvalTypeError: unsupported operand type(s) for *: 'numpy.ndarray' and 'numpy.ndarray'So, my question is how to fix this problem for the percentile calculation? Plus, would you please provide some help for step (2) and (3)? Thank you very much!
أكثر...