I've got a numpy array and need to sum the values in the rows. Then use the Update Cursor to update a field with this value. However the update cursor is updating the field with the same values.

tbl = arcpy.da.FeatureClassToNumPyArray(dg, ave_fields)

with arcpy.da.UpdateCursor(dg, "Weekly_Ave") as ucursor:
    for urow in ucursor:
        for i in range(len(tbl)):
            urow[0] = sum(tbl[i])
  • You only update the first column -- urow [0] vice urow[i]
    – Vince
    Aug 7 '17 at 21:07
  • I want to update each row with the sum of the values from the rows in tbl. The field is being updated with the same value over and over again. This isn't correct.
    – MacroZED
    Aug 7 '17 at 21:09

With each row you iterate through integers of the length of tbl (1, 2, 3, 4....) and update each row for each value. The final value will always be the last value in tbl. You'll need to get rid of your nested loop to fix the problem.

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