ArcGIS for Desktop

  • Documentation
  • Pricing
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS for Desktop

A complete professional GIS

ArcGIS for Server

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Pricing
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

Help

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • More...

NumPyArrayToTable

  • Summary
  • Discussion
  • Syntax
  • Code Sample

Summary

Converts a NumPy structured array to a table.

Discussion

If a field name from the input array is invalid for the output format, it will be validated. All invalid characters in the input field name are replaced with an underscore (_) in the output field name. Field name restrictions depend on the specific database used.

NumPyArrayToTable will not overwrite an existing table, even if the overwriteOutput environment is set to True.

NumPyArrayToTable only accepts structured arrays. If you have a regular NumPy ndarray, it will need to be first converted to a structured array. Below, we transpose the original array, and use the numpy.core.records.fromarrays method to create the new structured array.

import numpy
import arcpy
import os

a = numpy.array([(0.2, 1.0), (0.5, 2.5)])
struct_array = numpy.core.records.fromarrays(
    a.transpose(), numpy.dtype([('Value1', 'f8'), ('Value2', 'f8')]))

arcpy.da.NumPyArrayToTable(struct_array, 'c:/data/f.gdb/array_output')

NumPy is a fundamental package for scientific computing in Python, including support for a powerful N-dimensional array object. For more information, see Working with NumPy in ArcGIS.

Syntax

NumPyArrayToTable (in_array, out_table)
ParameterExplanationData Type
in_array

A NumPy structured array.

The array must include field names and NumPy dtypes.

NumPyArray
out_table

The table to which the records from the NumPy array will be written.

String

Code Sample

import arcpy
import numpy

# Create a simple array from scratch
#
inarray = numpy.array([('a', 1, 1111.0), ('b', 2, 2222.22)],
                      numpy.dtype([('textfield', '|S256'),
                                   ('intfield',numpy.int32),
                                   ('doublefield','<f8')]))

# Convert array to a geodatabase table
#
arcpy.da.NumPyArrayToTable(inarray, "c:/data/gdb.gdb/out_table")

import arcpy
import numpy

# Create a simple array from scratch using a list of values
#
recs = [['M', 64, 75.0],['F', 25, 60.0]]
dts = {'names': ('gender','age','weight'),
       'formats':('S1', numpy.uint8, numpy.float32)}
array = numpy.rec.fromrecords(recs, dtype=dts)

# Convert array to a geodatabase table
#
arcpy.da.NumPyArrayToTable(array, "c:/data/gdb.gdb/out_table")

Related Topics

  • NumPyArrayToFeatureClass
  • FeatureClassToNumPyArray
  • TableToNumPyArray
  • Working with NumPy in ArcGIS
  • ExtendTable
Feedback on this topic?

ArcGIS for Desktop

  • Home
  • Documentation
  • Pricing
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Insiders Blog
  • User Conference
  • Developer Summit
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | Privacy | Legal