def _factor_indexer(shape, labels):
 mult = np.array(shape)[::(-1)].cumprod()[::(-1)]
 return _ensure_platform_int(np.sum((np.array(labels).T * np.append(mult, [1])), axis=1).T)

def _factor_indexer ( shape , labels ) : mult = np . array ( shape ) [ : : ( - 1 ) ] . cumprod ( ) [ : : ( - 1 ) ] return _ensure_platform_int ( np . sum ( ( np . array ( labels ) . T * np . append ( mult , [ 1 ] ) ) , axis = 1 ) . T )
given a tuple of shape and a list of categorical labels .