I am trying to create a Python array using data from an ArcGIS attribute table. Here's the code I've written so far:

import arcpy
import numpy
input = "c:/data/from/arcgis"
arr = arcpy.da.TabletoNumPyArray(input,('OBJECTID','SoilEvap5'))
a = arr["OBJECTID"]
b = arr["SoilEvap5"]
print arr

When I try running this in the ArcGIS Python window, it returns:

Runtime error 
Traceback (most recent call last):
  File "<string>", line 7, in <module>
AttributeError: 'module' object has no attribute 'TabletoNumPyArray'

Why is this error showing up and how can I fix it?

  • What is it you're trying to do here? I can't see any arcpy commands (except import arcpy). What line gives you there error? – Michael Stimson Jul 20 '15 at 22:10
  • This is a very common error message: gis.stackexchange.com/… – PolyGeo Jul 20 '15 at 22:32
  • A good editor will help you avoid this sort of problem. I use PyWin which has some basic InteliSense (you type in arcpy.da. and all the methods available appear)... saves typing and avoids mistyping/incorrect case. Other editors no doubt can do this and IMO it's worth finding a good one. – Michael Stimson Jul 20 '15 at 22:50
  • I am still happy to just work with IDLE as my Python editor because it also has code completion ("IntelliSense") - stackoverflow.com/a/16467896/820534 - but to see that you need to put import arcpy and run your code once first. Also, to force it to auto complete using Ctrl-spacebar is a trick worth knowing. – PolyGeo Jul 20 '15 at 22:55

The correct name for this function is TableToNumPyArray (arcpy.da) i.e. there should be a capital "T" on "to".

Correct capitalization is very important to the Python programming language.

  • should the field names be a tuple ('OBJECTID','SoilEvap5') or list ['OBJECTID','SoilEvap5'] or doesn't that matter in this case? Where tools say [field_names,...] I have interpreted that as a list but it wouldn't surprise me if a tuple could be substituted. – Michael Stimson Jul 20 '15 at 22:47
  • 1
    @MichaelMiles-Stimson I think lists and tuples are interchangeable within at least some (perhaps all) ArcPy functions but I've not tested to say with 100% confidence. – PolyGeo Jul 20 '15 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.