def _reshape_2D(X):
 if hasattr(X, u'shape'):
  if (len(X.shape) == 1):
   if hasattr(X[0], u'shape'):
    X = list(X)
   else:
    X = [X]
  elif (len(X.shape) == 2):
   (nrows, ncols) = X.shape
   if (nrows == 1):
    X = [X]
   elif (ncols == 1):
    X = [X.ravel()]
   else:
    X = [X[:, i] for i in xrange(ncols)]
  else:
   raise ValueError(u'input `X` must have 2 or fewer dimensions')
 if (not hasattr(X[0], u'__len__')):
  X = [X]
 else:
  X = [np.ravel(x) for x in X]
 return X

def _reshape_2D ( X ) : if hasattr ( X , u'shape' ) : if ( len ( X . shape ) == 1 ) : if hasattr ( X [ 0 ] , u'shape' ) : X = list ( X ) else : X = [ X ] elif ( len ( X . shape ) == 2 ) : ( nrows , ncols ) = X . shape if ( nrows == 1 ) : X = [ X ] elif ( ncols == 1 ) : X = [ X . ravel ( ) ] else : X = [ X [ : , i ] for i in xrange ( ncols ) ] else : raise ValueError ( u'input `X` must have 2 or fewer dimensions' ) if ( not hasattr ( X [ 0 ] , u'__len__' ) ) : X = [ X ] else : X = [ np . ravel ( x ) for x in X ] return X
converts a non-empty list or an ndarray of two or fewer dimensions into a list of iterable objects so that in for v in _reshape_2d(x): v is iterable and can be used to instantiate a 1d array .