def two_way(cells):
<EOL>warnings.simplefilter("<STR_LIT:ignore>", RuntimeWarning)<EOL>cells = cells.astype('<STR_LIT>')  <EOL>total = np.apply_over_axes(np.sum, cells, [<NUM_LIT:1>, <NUM_LIT:2>]).ravel()<EOL>chi_sq = np.zeros(cells.shape, dtype='<STR_LIT>')<EOL>for i in range(<NUM_LIT:2>):<EOL><INDENT>for j in range(<NUM_LIT:2>):<EOL><INDENT>exp = np.sum(cells[:, i, :], <NUM_LIT:1>).ravel() *np.sum(cells[:, :, j], <NUM_LIT:1>).ravel() / total<EOL>bad_vox = np.where(exp == <NUM_LIT:0>)[<NUM_LIT:0>]<EOL>chi_sq[:, i, j] = (cells[:, i, j] - exp) ** <NUM_LIT:2> / exp<EOL>chi_sq[bad_vox, i, j] = <NUM_LIT:1.0>  <EOL><DEDENT><DEDENT>chi_sq = np.apply_over_axes(np.sum, chi_sq, [<NUM_LIT:1>, <NUM_LIT:2>]).ravel()<EOL>return special.chdtrc(<NUM_LIT:1>, chi_sq)<EOL>
Two-way chi-square test of independence.
    Takes a 3D array as input: N(voxels) x 2 x 2, where the last two dimensions
    are the contingency table for each of N voxels. Returns an array of
    p-values.