#NEWLINE# def group_sums( x , group , use_bincount = True ) : #NEWLINE# #INDENT# 'simple bincount version, again\n\n    group : array, integer\n        assumed to be consecutive integers\n\n    no dtype checking because I want to raise in that case\n\n    uses loop over columns of x\n\n    for comparison, simple python loop\n    ' #NEWLINE# x = np . asarray ( x ) #NEWLINE# if ( x . ndim == 1 ) : #NEWLINE# #INDENT# x = x [ : , None ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( x . ndim > 2 ) and use_bincount ) : #NEWLINE# #INDENT# raise ValueError ( 'not implemented yet' ) #NEWLINE# #UNINDENT# #UNINDENT# if use_bincount : #NEWLINE# #INDENT# if ( np . max ( group ) > ( 2 * x . shape [ 0 ] ) ) : #NEWLINE# #INDENT# group = pd . factorize ( group ) [ 0 ] #NEWLINE# #UNINDENT# return np . array ( [ np . bincount ( group , weights = x [ : , col ] ) for col in range ( x . shape [ 1 ] ) ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# uniques = np . unique ( group ) #NEWLINE# result = np . zeros ( ( [ len ( uniques ) ] + list ( x . shape [ 1 : ] ) ) ) #NEWLINE# for ( ii , cat ) in enumerate ( uniques ) : #NEWLINE# #INDENT# result [ ii ] = x [ ( g == cat ) ] . sum ( 0 ) #NEWLINE# #UNINDENT# return result