title: Merging NumPy arrays and finding columns in Python
body: <p>I am new to Python. I have two data files in CSV format. I loaded the CSV files data into two NumPy arrays:</p>
  
  <pre><code>matrix1 = numpy.genfromtxt(fileName1)
  matrix2 = numpy.genfromtxt(fileName2)
  </code></pre>
  
  <p>The rows and cols of both the matrices are unequal.</p>
  
  <pre><code>&gt;&gt;print(matrix1.shape)
  (971, 4413)
  &gt;&gt;print(matrix2.shape)
  &gt;&gt;(5504, 4431)
  </code></pre>
  
  <p>I want to combine matrix1 and matrix2 in such a way:</p>
  
  <pre><code>mergedMatrix = [ matrix1, matrix2 ]
  </code></pre>
  
  <p>where I can access <code>matrix1</code> from <code>mergedMatrix</code> using index <code>0</code> and <code>matrix2</code> using index <code>1</code>.</p>
  
  <p>I tried to use <code>numpy.concatenate</code> but it does not works on these two matrices. So I tried using pandas merge function after converting <code>matrix1</code> and <code>matrix2</code> into pandas DataFrames. However, it took a lot of time to do so and all the matrices were merged into a single linear array like <code>[1, 2, 3,4,5...]</code> and I didn't had any way to distinguish between <code>matrix1</code> and <code>matrix2</code> in <code>mergedMatrix</code>.</p>
  
  <p>So I am using:</p>
  
  <pre><code>#mergedMatrix as a list
  mergedMatrix = [matrix1, matrix2]
  </code></pre>
  
  <p>My data contains values like <code>Inf</code>. If a column contains value <code>Inf</code> in <code>matrix1</code> the I want to delete that column as well as the corresponding column i.e. the column with the same column number in <code>matrix2</code>.</p>
  
  <h3>Questions</h3>
  
  <ol>
  <li>Is there a better way than to use a list <code>mergedMatrix</code>?</li>
  <li>How can find if a <code>matrix1</code> column contains such values quickly without checking each element one by one and its column number?</li>
  </ol>
  
  <h3>Example:</h3>
  
  <pre><code>matrix1 = [[1, 2, 3],
             [3, inf,0],
             [2 , inf, inf]]
  matrix2 = [[0, 4, 2, 7],
             [0, 1, 0.5, 3],
             [1, 2, 3, 9]]
  
  mergedMatrix = [[1, 2, 3],
             [3, inf,0],
             [2 , inf, inf],
             [0, 4, 2, 7],
             [0, 1, 0.5, 3],
             [1, 2, 3, 9]]
  </code></pre>
  
  <p>The result should be:</p>
  
  <pre><code>mergedMatrix = [[1],
                  [3],
                  [2],
                  [0,7],
                  [0,3],
                  [1,9]]
  
  removedMatrixCols = [[2, 3],
                 [inf,0],
                 [inf, inf],
                 [4, 2],
                 [1, 0.5],
                 [2, 3]]
  </code></pre>
  
  <p>Then I want to split the matrices:</p>
  
  <pre><code>newMatrix1 = [[1],
                [3],
                [2]]
  newMatrix2 = [[0,7],
                [0,3],
                [1,9]]
  
  removedCols1 = [[2, 3],
                  [inf,0],
                  [inf, inf]]
  
  removedCols2 = [[4, 2],
                  [1, 0.5],
                  [2, 3]]
  </code></pre>
  
  <p>so that I can store them into CSV files separately.</p>