Your friend einsum.... The lengths are in sequential clockwise order from the start point (you can always determine/produce polygon points either as a separate feature class or values in a table.)
def lengths(poly):
"""Polyline lengths or polygon perimeter."""
def _cal(a):
"""Perform the calculation, mini-e_leng."""
diff = a[:-1] - a[1:]
return np.sqrt(np.einsum('ij,ij->i', diff, diff))
return _cal(poly)
[lengths(p) for p in [b1, b2, b3, b4]]
[array([ 10.0, 10.0, 10.0, 10.0]),
array([ 10.0, 11.2, 11.2]),
array([ 11.2, 10.0, 11.2]),
array([ 11.2, 11.2, 10.0])]
b1
array([[ 10.0, 0.0],
[ 10.0, 10.0],
[ 20.0, 10.0],
[ 20.0, 0.0],
[ 10.0, 0.0]])
b2
array([[ 20.0, 0.0],
[ 20.0, 10.0],
[ 30.0, 5.0],
[ 20.0, 0.0]])
b3
array([[ 15.0, 20.0],
[ 20.0, 10.0],
[ 10.0, 10.0],
[ 15.0, 20.0]])
b4
array([[ 10.0, 0.0],
[ 0.0, 5.0],
[ 10.0, 10.0],
[ 10.0, 0.0]])