Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are you needing this to calculate <a href="http://en.wikipedia.org/wiki/Fisher%27s_exact_test" rel="nofollow noreferrer">Fisher's exact test</a>? Because that requires what you're doing, and based on that page, it seems there will in general be a vast number of solutions, so you probably can't do better than a brute force recursive enumeration if you want every solution. OTOH it seems Monte Carlo approximations are successfully used by some software instead of full-blown enumerations.</p> <p>I asked a <a href="https://stackoverflow.com/questions/5086872/is-it-possible-to-shuffle-a-2d-matrix-while-preserving-row-and-column-frequencie">similar question</a>, which might be helpful. Although that question deals with preserving frequencies of letters in each row and column rather than sums, some results can be translated across. E.g. if you find any submatrix (pair of not-necessarily-adjacent rows and pair of not-necessarily-adjacent columns) with numbers</p> <pre><code>xy yx </code></pre> <p>Then you can rearrange these to</p> <pre><code>yx xy </code></pre> <p>without changing any row or column sums. However:</p> <ul> <li><a href="https://stackoverflow.com/a/5087786/47984">mhum's answer</a> proves that there will in general be valid matrices that cannot be reached by any sequence of such 2x2 swaps. This can be seen by taking his 3x3 matrices and mapping <code>A -&gt; 1</code>, <code>B -&gt; 2</code>, <code>C -&gt; 4</code> and noticing that, because no element appears more than once in a row or column, frequency preservation in the original matrix is equivalent to sum preservation in the new matrix. <em>However...</em></li> <li><a href="https://stackoverflow.com/a/5091273/47984">someone's answer</a> links to a mathematical proof that it actually will work for matrices whose entries are just 0 or 1.</li> </ul> <p>More generally, if you have any submatrix</p> <pre><code>ab cd </code></pre> <p>where the (not necessarily unique) minimum is d, then you can replace this with any of the d+1 matrices</p> <pre><code>ef gh </code></pre> <p>where h = d-i, g = c+i, f = b+i and e = a-i, for any integer 0 &lt;= i &lt;= d.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload