A followup to the recent einsum post, but with a field calculator twist
# ---- a numeric field, python expression which uses the shape field to return the longest edge on the perimeter
longest_seg(!Shape!)
# ---- the code block -----
import json
import numpy as np
#
def longest_seg(a):
"""Longest edge"""
v = json.loads(a.JSON)
r = v['rings']
a = np.array(r).squeeze()
a = a[0] if a.ndim > 2 else a
diff = a[1:] - a[:-1]
ret = np.sqrt(np.einsum('ij,ij->i', diff, diff))
val = np.max(ret)
return val
lines 12-13 : really? having to convert to JSON format just to get at the array values?