def row_norms(ii, f=Ellipsis, squared=False):
try:<EOL><INDENT>(n,m) = ii<EOL>ii = np.reshape(np.arange(n*m), (n,m))<EOL><DEDENT>except Exception: ii = np.asarray(ii)<EOL>f = to_potential(f)<EOL>if is_const_potential(f):<EOL><INDENT>q = flattest(f.c)<EOL>q = np.sum([q[i]**<NUM_LIT:2> for i in ii.T], axis=<NUM_LIT:0>)<EOL>return PotentialConstant(q if squared else np.sqrt(q))<EOL><DEDENT>F = reduce(lambda a,b: a + b, [part(Ellipsis, col)**<NUM_LIT:2> for col in ii.T])<EOL>F = compose(F, f)<EOL>if not squared: F = sqrt(F)<EOL>return F<EOL>
row_norms(ii) yields a potential function h(x) that calculates the vector norms of the rows of
  the matrix formed by [x[i] for i in ii] (ii is a matrix of parameter indices).
row_norms(ii, f) yield a potential function h(x) equivalent to compose(row_norms(ii), f).