#NEWLINE# def sum( self , axis ) : #NEWLINE# #INDENT# '\n        Sums up all values along the given axis.\n        :param axis: 0 for summing along the rows, 1 for summing along the cols.\n        :return:\n        ' #NEWLINE# if ( axis not in ( 0 , 1 ) ) : #NEWLINE# #INDENT# raise ValueError ( 'Axis must be 0 or 1' ) #NEWLINE# #UNINDENT# summed = self . matrix . sum ( axis = axis ) #NEWLINE# if ( axis == 0 ) : #NEWLINE# #INDENT# return self . _new_instance ( summed , row2word = [ '' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( summed == 1 ) : #NEWLINE# #INDENT# return self . _new_instance ( summed , col2word = [ '' ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Axis may only be 0 (rows) or 1 (cols)' )