NumPyArrayToTable

サマリー

NumPy 構造化配列をテーブルに変換します。

説明

入力配列のフィールド名が出力形式で無効である場合、整合チェックされます。 入力フィールド名のすべての無効な文字は、出力フィールド名では下線 (_) に置き換えられます。 フィールド名の制限は、使用されるデータベースによって異なります。

NumPyArrayToTable は、overwriteOutput 環境が True に設定されていても、既存のテーブルを上書きしません。

NumPyArrayToTable は、構造化配列のみを指定できます。 通常の NumPy ndarray は、まず構造化配列に変換する必要があります。 以下では、元の配列を置換して、numpy.core.records.fromarrays メソッドを使用して新しい構造化配列を作成します。

import numpy
import arcpy

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.

構文

NumPyArrayToTable (in_array, out_table)
パラメーター説明データ タイプ
in_array

NumPy 構造化配列。

配列には、フィールド名と NumPy dtype が含まれている必要があります。

NumPyArray
out_table

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

String

コードのサンプル

NumPyArrayToTable の例 1
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")
NumPyArrayToTable の例 2
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")

関連トピック