title: Generating linear combination of a matrix
body: <p>I want to create a matrix A [4x8] as follows.</p>
  
  <p>The matrix A always has <code>1</code> as its diagonal. <code>A11,A22,A33,A44 = 1</code></p>
  
  <p>This matrix can be considered as two halves with first half being the first 4 columns and the second half being the second 4 columns like something below : </p>
  
  <pre><code>        1 -1 -1 -1   1 0 0 1
    A =  -1  1 -1  0   0 1 0 0
         -1 -1  1  0   1 0 0 0 
         -1 -1 -1  1   1 1 0 0
  </code></pre>
  
  <p>Each row in the first half can have either two or three -1's:</p>
  
  <ul>
  <li>if it has two <code>-1</code>'s then that corresponding row in the second half should have one <code>1</code></li>
  <li>if any row has three <code>-1</code>'s the second half of the matrix should have two <code>1</code>'s.</li>
  </ul>
  
  <p>The overall objective is to have the sum of each row to be <code>0</code>. I need to generate all possible combinations of a matrix like this.</p>
  
  <p>It will be better if the matrix with new combination be created at each iteration so that after using it I can discard it or else storing all the combinations is very space intensive. Can anybody help me ? </p>
  
  <p>one possible solution I could think of is to generate all possible combinations of row1, row2, row3 and row4 and create a matrix in each iteration. Does that look feasible?</p>