title: How to swap columns and rows in a matrix with Ruby
body: <p>All I want to do is swap <code>matrix[i][j]</code> with <code>matrix[j][i]</code> using <code>while</code> loops. Why doesn't this work?</p>
  
  <pre><code>def my_transpose(matrix)
  
    new_matrix = []
  
    i = 0
    j = 0
  
    while i &lt; matrix.size
      new_matrix[i] = []
      while j &lt; matrix.size
        new_matrix[i] &lt;&lt; matrix[j][i]
        j += 1
      end
      i += 1
    end
  
    return new_matrix
  end
  </code></pre>
  
  <p>If I run this with something like </p>
  
  <pre><code>[
  [1,2,3],
  [1,2,3],
  [1,2,3]
  ]
  </code></pre>
  
  <p>it just returns <code>1,1,1</code>. How do I get it to return <code>1,1,1; 2,2,2; 3,3,3</code> ? </p>