I am trying to get acquainted with numpy and point feature classes in ArcGIS and I started with what I thought was an simple example.
I am reading in a single part point feature class (contains fields named: X, Y and YR) via FeatureClassToNumPyArray. I am interested in finding the 'max' value within a given field using numpy.
A snippet of my code is below:
array <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>FeatureClassToNumPyArray<SPAN class="punctuation token">(</SPAN>inputFC<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"X"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Y"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"YR"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> array<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
It prints:
[(2531050.0, 7431830.0, 2018.0) (2531050.0, 7431810.0, 2018.0)
(2531050.0, 7431850.0, 2018.0) (2531050.0, 7431930.0, 2018.0)
(2531050.0, 7431890.0, 2018.0) (2531050.0, 7431870.0, 2018.0)
(2531050.0, 7431910.0, 2018.0) (2531050.0, 7431950.0, 2018.0)
(2531050.0, 7431970.0, 2018.0) (2531050.0, 7432030.0, 2018.0)
(2531070.0, 7428230.0, 2018.0)]<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
A slight change in the code attempts to get the max for each column by specifying axis = 0:
array <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>FeatureClassToNumPyArray<SPAN class="punctuation token">(</SPAN>inputFC<SPAN class="punctuation token">,</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"X"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Y"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"YR"</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> numpy<SPAN class="punctuation token">.</SPAN>amax<SPAN class="punctuation token">(</SPAN>array<SPAN class="punctuation token">,</SPAN> axis <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN></SPAN>
However the script output is:
File "work5_EFI_sum.py", line 102, in <module>
doSummary()
File "work5_EFI_sum.py", line 20, in doSummary
print numpy.amax(array, axis = 0)
File "C:\Python27\ArcGIS10.6\lib\site-packages\numpy\core\fromnumeric.py", line 2140, in amax
out=out, keepdims=keepdims)
File "C:\Python27\ArcGIS10.6\lib\site-packages\numpy\core\_methods.py", line 26, in _amax
return umr_maximum(a, axis, None, out, keepdims)
TypeError: cannot perform reduce with flexible type<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Any idea on what's going on?