3

I'm new at Python but I want to either assign or reference specific values from a feature class of earthquake data in a Python script to be used in a custom function. I've tried using Feature Class To NumPy Array as the following:

eq = arcpy.da.FeatureClassToNumPyArray('wells_eq', fields)

When I print the result, this is what is returned:

>>> print eq [(41.144, -114.872, 1.6, 1.6, 1.9, 10.0, 21.0, 212.0, 71.0)]

I want to assign a variable, such as strike1 and dip1. I tried

strike1 = eq[5] but got

Traceback (most recent call last): File "<interactive input>", line 1, in <module> IndexError: index 5 is out of bounds for axis 0 with size 1

As a check for indexing, I tried

>>> print eq[0] (41.144, -114.872, 1.6, 1.6, 1.9, 10.0, 21.0, 212.0, 71.0)

So my question is, how can either I make individual variables based on the values in the feature class, or reference those values to be used in a custom function? Or should I try a different approach altogether?

3

Your list has only one item in it which is a tuple.

To see the sixth item in that tuple use:

print eq[0][5]

I think of this as being that I am printing the 6th item in the first item in the list object called eq.

2
  • Thanks! That worked. So the first bracket calls the tuple and the second calls the desired element within the tuple?
    – Brandon
    Nov 18 '16 at 0:53
  • Yes - I think of it as being that I am printing the 6th item in the first item in the list object called eq.
    – PolyGeo
    Nov 18 '16 at 0:56
1
eq = (41.144, -114.872, 1.6, 1.6, 1.9, 10.0, 21.0, 212.0, 71.0)

strike1, dip1, ht1, wt1, ... ,lt1 = eq

Be sure to make your number of variables be almost close to the number of items in 'eq'

print(strike1)

to see 41.144

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.