def com_find2D(ar_grid, **kwargs):
b_reorder   = True<EOL>b_oneOffset = True<EOL>for key, value in kwargs.items():<EOL><INDENT>if key == '<STR_LIT>' and value == '<STR_LIT>':         b_reorder       = False<EOL>if key == '<STR_LIT>' and value == '<STR_LIT>':         b_reorder       = True<EOL>if key == '<STR_LIT>' and value == '<STR_LIT>':       b_oneOffset     = False<EOL>if key == '<STR_LIT>' and value == '<STR_LIT>':        b_oneOffset     = True<EOL><DEDENT>f_Smass = ar_grid.sum()<EOL>f_comX = (ar_grid[nonzero(ar_grid)] * (nonzero(ar_grid)[<NUM_LIT:1>] + <NUM_LIT:1>)).sum() / f_Smass<EOL>f_comY = (ar_grid[nonzero(ar_grid)] * (nonzero(ar_grid)[<NUM_LIT:0>] + <NUM_LIT:1>)).sum() / f_Smass<EOL>if b_reorder:       ar_ret = array( (f_comX, f_comY) )<EOL>if not b_reorder:   ar_ret = array( (f_comY, f_comX) )<EOL>if not b_oneOffset: ar_ret -= <NUM_LIT:1.0><EOL>return ar_ret<EOL>
ARGS
**kwargs
    ordering = 'rc' or 'xy'        order the return either in (x,y)
                                   or (row, col) order.
    indexing = 'zero' or 'one'     return positions relative to zero (i.e.
                                   python addressing) or one (i.e. MatLAB
                                   addressing)

DESC
    Find the center of mass in 2D array grid <ar_grid>. Mass elements
    are grid index values.

    By using python idioms, his version is MUCH faster than the com_find()