def tosequence(x):
 if isinstance(x, np.ndarray):
  return np.asarray(x)
 elif isinstance(x, Sequence):
  return x
 else:
  return list(x)

def tosequence ( x ) : if isinstance ( x , np . ndarray ) : return np . asarray ( x ) elif isinstance ( x , Sequence ) : return x else : return list ( x )
cast iterable x to a sequence .