# TableToNumPyArray

## 说明

NumPy 是 Python 中用于进行科学计算的基础包，其包括支持功能强大的 N 维数组对象。有关详细信息，请参阅在 ArcGIS 中使用 NumPy

## 语法

`TableToNumPyArray (in_table, field_names, {where_clause}, {skip_nulls}, {null_value})`

in_table

String
field_names
[field_names,...]

• OID@Returns the value of the ObjectID field.

(默认值为 *)

String
where_clause

(默认值为 "")

String
skip_nulls

``````import arcpy
array = arcpy.da.TableToNumPyArray(table, fields, skip_nulls=True)``````

``````import arcpy

def getnull(oid):
nullRows.append(oid)
return True

nullRows = list()
array = arcpy.da.TableToNumPyArray(table, fields, skip_nulls=getnull)
print(nullRows)``````

``````import arcpy
nullRows = list()
array = arcpy.da.TableToNumPyArray(
table, fields, skip_nulls=lambda oid: nullRows.append(oid))
print(nullRows)``````

##### 注：

(默认值为 False)

Variant
null_value

Mask None values in integer fields with a -9999.

``````import arcpy
fields = ['field1', 'field2']
arcpy.da.TableToNumPyArray(table, fields, null_value=-9999)``````

Mask None values in integer fields with different values using a dictionary.

``````import arcpy
fields = ['field1', 'field2']
nullDict = {'field1':-999999, 'field2':-9999}
arcpy.da.TableToNumPyArray(table, fields, null_value=nullDict)``````
##### 警告：

(默认值为 None)

Integer

 数据类型 说明 NumPyArray NumPy 结构化数组。

## 代码示例

TableToNumPyArray 示例 1

``````import arcpy
import numpy

input = "c:/data/usa.gdb/USA/counties"
arr = arcpy.da.TableToNumPyArray(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())``````
TableToNumPyArray 示例 2

``````import arcpy
import numpy

input = arcpy.GetParameterAsText(0)
field1 = arcpy.GetParameterAsText(1)
field2 = arcpy.GetParameterAsText(2)

arr = arcpy.da.TableToNumPyArray(input, (field1, field2))

# Print correlation coefficients for comparison of 2 field values
print(numpy.corrcoef((arr[field1], arr[field2])))``````