FeatureClassToNumPyArray
Summary
The FeatureClassToNumPyArray function converts a feature class to NumPy structured array.
Discussion
NumPy is a fundamental package for scientific computing in Python, including support for a powerful N-dimensional array object. For more information, see NumPy in ArcGIS.
To convert tables to a NumPy array, use the TableToNumPyArray function instead.
Syntax
FeatureClassToNumPyArray(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {skip_nulls}, {null_value})
| Parameter | Explanation | Data Type |
|---|---|---|
|
in_table |
The feature class, layer, table, or table view. |
String |
|
field_names |
A list (or tuple) of field names. For a single field, you can use a string instead of a list of strings. Use an asterisk ( Raster and BLOB fields are not supported. Geometry objects are not supported using the Additional information can be accessed using tokens (such as
Export a feature class to a NumPy array. The output array will include a field for the Object ID and a field containing a tuple of the feature's centroid's x,y coordinates.
The default value is *. |
String |
|
where_clause |
An optional expression that limits the records returned. For more information on WHERE clauses and SQL statements, see SQL reference for query expressions used in ArcGIS. The default value is "". |
String |
|
spatial_reference |
The spatial reference of the feature class. When this argument is specified, the feature will be projected (or transformed) from the input's spatial reference. If unspecified, the input feature classes' spatial reference will be used. Valid values for this argument are a Use the spatial_reference argument to return coordinates in a different spatial reference. Here, a second feature class is described to access a spatial reference object.
The default value is None. |
SpatialReference |
|
explode_to_points |
Deconstruct a feature into its individual points or vertices. If The default value is False. |
Boolean |
|
skip_nulls |
Control whether records using nulls are skipped. It can be either a Boolean When set to Skip all records that include a null.
A Python function or Use a function to capture all records that are skipped because of nulls.
Use a lambda expression to capture all records that are skipped because of nulls.
Note:In NumPy arrays, nulls are represented in float types such as The default value is False. |
Variant |
|
null_value |
Replaces null values from the input with a new value.
Mask all None's in integer fields with a -9999.
Mask None's in integer fields with different values using a dictionary.
Caution:Providing a mask such as -9999 allows integer fields containing nulls to be exported to a NumPy array, but be cautious when using these values in any analysis. The results may be inadvertently skewed by the introduced value. The default value is None. |
Integer |
Return value
| Data Type | Explanation |
|---|---|
|
NumPyArray |
A NumPy structured array. |
Code sample
Convert a table to a numpy array and perform some basic statistics with numpy.
import arcpy
import numpy
input = "c:/data/usa.gdb/USA/counties"
arr = arcpy.da.FeatureClassToNumPyArray(input, ('STATE_NAME', 'POP1990', 'POP2000'))
# Sum the total population for 1990 and 2000
print(arr["POP1990"].sum())
print(arr["POP2000"].sum())
# Sum the population for the state of Minnesota
print(arr[arr['STATE_NAME'] == "Minnesota"]['POP2000'].sum())
Use TableToNumPyArray to determine correlation coefficients for two fields.
import arcpy
import numpy
input = "c:/data/usa.gdb/USA/counties"
field1 = "INCOME"
field2 = "EDUCATION"
arr = arcpy.da.FeatureClassToNumPyArray(input, (field1, field2))
# Print correlation coefficients for comparison of 2 field values
print(numpy.corrcoef((arr[field1], arr[field2])))