def frt2(a):
 if ((a.ndim != 2) or (a.shape[0] != a.shape[1])):
  raise ValueError('Input must be a square, 2-D array')
 ai = a.copy()
 n = ai.shape[0]
 f = np.empty(((n + 1), n), np.uint32)
 f[0] = ai.sum(axis=0)
 for m in range(1, n):
  for row in range(1, n):
   ai[row] = roll(ai[row], (- row))
  f[m] = ai.sum(axis=0)
 f[n] = ai.sum(axis=1)
 return f

def frt2 ( a ) : if ( ( a . ndim != 2 ) or ( a . shape [ 0 ] != a . shape [ 1 ] ) ) : raise ValueError ( 'Input must be a square, 2-D array' ) ai = a . copy ( ) n = ai . shape [ 0 ] f = np . empty ( ( ( n + 1 ) , n ) , np . uint32 ) f [ 0 ] = ai . sum ( axis = 0 ) for m in range ( 1 , n ) : for row in range ( 1 , n ) : ai [ row ] = roll ( ai [ row ] , ( - row ) ) f [ m ] = ai . sum ( axis = 0 ) f [ n ] = ai . sum ( axis = 1 ) return f
compute the 2-dimensional finite radon transform for an n x n integer array .