def data2dummy(x, returnall=False):
 x = x.ravel()
 groups = np.unique(x)
 if returnall:
  return (x[:, None] == groups).astype(int)
 else:
  return (x[:, None] == groups).astype(int)[:, :(-1)]

def data2dummy ( x , returnall = False ) : x = x . ravel ( ) groups = np . unique ( x ) if returnall : return ( x [ : , None ] == groups ) . astype ( int ) else : return ( x [ : , None ] == groups ) . astype ( int ) [ : , : ( - 1 ) ]
convert array of categories to dummy variables by default drops dummy variable for last category uses ravel .