Grant, could you use /blogs/dan_patterson/2016/08/14/script-formatting
your indentation looks a bit off and the actual line numbers would help.
1. any nodata in your data set? if so, use np.nanpercentile …
2, your problem is that when you use da.FeatureClassToNumPyArray, you still have a structured array
b = arcpy.da.FeatureClassToNumPyArray(in_fc, 'Doubles')
b
array([(1.2,), (1.4,), (1.8,), (1.6,), (1.9,), (1.1,), (1.3,), (1.5,), (1.7,)],
dtype=[('Doubles', '<f8')])
np.percentile(b, (25, 50, 75))
Traceback (most recent call last):
TypeError: invalid type promotion
Now recent versions of numpy have added a couple of helper functions. My favs are 'stu' (readup on it on GitHub on in the help for numpy)
from numpy.lib.recfunctions import structured_to_unstructured as stu
b
array([(1.2,), (1.4,), (1.8,), (1.6,), (1.9,), (1.1,), (1.3,), (1.5,), (1.7,)],
dtype=[('Doubles', '<f8')])
a = stu(b)
np.percentile(a, (25, 50, 75))
array([1.3, 1.5, 1.7])
And 'stu' has an alter ego … 'uts' to go the other way, making an ndarray into a structured array. There is some technical details about repacking fields for some types of arrays, but read up on the discussion on the numpy discussion archive or on GitHub.
from numpy.lib.recfunctions import unstructured_to_structured as uts
from numpy.lib.recfunctions import repack_fields