def companion(a):
 a = np.atleast_1d(a)
 if (a.ndim != 1):
  raise ValueError('Incorrect shape for `a`.  `a` must be one-dimensional.')
 if (a.size < 2):
  raise ValueError('The length of `a` must be at least 2.')
 if (a[0] == 0):
  raise ValueError('The first coefficient in `a` must not be zero.')
 first_row = ((- a[1:]) / (1.0 * a[0]))
 n = a.size
 c = np.zeros(((n - 1), (n - 1)), dtype=first_row.dtype)
 c[0] = first_row
 c[(list(range(1, (n - 1))), list(range(0, (n - 2))))] = 1
 return c

def companion ( a ) : a = np . atleast_1d ( a ) if ( a . ndim != 1 ) : raise ValueError ( 'Incorrect shape for `a`.  `a` must be one-dimensional.' ) if ( a . size < 2 ) : raise ValueError ( 'The length of `a` must be at least 2.' ) if ( a [ 0 ] == 0 ) : raise ValueError ( 'The first coefficient in `a` must not be zero.' ) first_row = ( ( - a [ 1 : ] ) / ( 1.0 * a [ 0 ] ) ) n = a . size c = np . zeros ( ( ( n - 1 ) , ( n - 1 ) ) , dtype = first_row . dtype ) c [ 0 ] = first_row c [ ( list ( range ( 1 , ( n - 1 ) ) ) , list ( range ( 0 , ( n - 2 ) ) ) ) ] = 1 return c
create a companion matrix .