title: Python: Concatenation of elements in different matrices
body: <p>I have some issues in trying to concatenate strings in two different matrices between each other.
  Example:</p>
  <ul>
  <li>The first matrix is dat defines as follows</li>
  </ul>
  <pre><code>
  dat = array([['data 1:1 ', 'data 2:2 '],
         ['data 1:1 ', 'data 2:2 '],
         ['data 1:1 ', 'data 2:2 ']], dtype='&lt;U9')
  </code></pre>
  <ul>
  <li>The second matix is defined as:</li>
  </ul>
  <pre><code>sp = array([['sim_spec_A0_grp25.pha', 'sim_spec_B0_grp25.pha'],
         ['sim_spec_A1_grp25.pha', 'sim_spec_B1_grp25.pha'],
         ['sim_spec_A2_grp25.pha', 'sim_spec_B2_grp25.pha']], dtype='&lt;U21')
  </code></pre>
  <p>I would like to obtain the following result:</p>
  <pre><code>my_matrix =  ['data 1:1 sim_spec_A0_grp25.pha', 'data 2:2 sim_spec_B0_grp25.pha'],
               ['data 1:1 sim_spec_A1_grp25.pha', 'data 2:2 sim_spec_B1_grp25.pha']
               ['data 1:1 sim_spec_A2_grp25.pha', 'data 2:2 sim_spec_B2_grp25.pha']]
  </code></pre>
  <p>I tried to implemet the following solution:</p>
  <pre><code>nset = 3
  dim = 2
  
  my_matrix = np.matrix(np.zeros((nset,dim)), dtype='str')
  
  for i in range(0,nset):
      for j in range(0,dim):
          my_matrix[i][j]=dat[i][j]+sp[i][j]
  </code></pre>
  <p>obtaining the following error:</p>
  <pre><code>
  Traceback (most recent call last):
  
    File &quot;&lt;ipython-input-470-e62722962bc7&gt;&quot;, line 5, in &lt;module&gt;
      my_matrix[i][j]=dat[i][j]+sp[i][j]
  
    File &quot;/opt/anaconda3/lib/python3.7/site-packages/numpy/matrixlib/defmatrix.py&quot;, line 195, in __getitem__
      out = N.ndarray.__getitem__(self, index)
  
  IndexError: index 1 is out of bounds for axis 0 with size 1
  
  </code></pre>
  <p>How can I solve the problem?</p>
  <p>In addition, once the final matrix is built, is it possible to obtain a second matrix as follows?</p>
  <pre><code>Final =      ['data 1:1 sim_spec_A0_grp25.pha   data 2:2 sim_spec_B0_grp25.pha'],
               ['data 1:1 sim_spec_A1_grp25.pha   data 2:2 sim_spec_B1_grp25.pha']
               ['data 1:1 sim_spec_A2_grp25.pha  data 2:2 sim_spec_B2_grp25.pha']]
  </code></pre>
  <p>Thank you in advance for your help and availability!</p>