title: How do I parse an array/matrix from a text file while preserving its structure?
body: <p>I am new to python and am trying to write a script that will parse the data contained between each pair of headers in the text file below. </p>
  
  <pre><code>&lt;Keywords&gt; 
  GTO
  &lt;/Keywords&gt;
  &lt;NumberofNuclei&gt;
  2
  &lt;/NumberofNuclei&gt;
  &lt;Nuclear Charges&gt; 
  6.0
  8.0
  1.0
  1.0
  &lt;/Nuclear Charges&gt;
  &lt;Primitive Exponents&gt;
  8.264000000000e+01  1.241000000000e+01  2.824000000000e+00   
  8.989000000000e-02  2.292000000000e+00  2.292000000000e+00  
  8.380000000000e-01  8.380000000000e-01  2.920000000000e-01 
  &lt;/Primitive Exponents&gt;
  </code></pre>
  
  <p>My attempt at a code that can do this is shown below. However, I am having difficulty parsing the matrix under Primitive Exponents while preserving its 3x3 structure. I don't want it written as a list. </p>
  
  <pre><code>with open('toysystem.txt','r') as f:
   data = f.read()
   nc = re.findall(r'&lt;Nuclear Charges&gt;(.*?)&lt;/Nuclear Charges&gt;',data,re.DOTALL)
   nc1 = [elem.replace('\n',',').strip(',') for elem in nc]
   non = re.findall(r'&lt;NumberofNuclei&gt;(.*?)&lt;/NumberofNuclei&gt;',data,re.DOTALL)
   non1 = int("".join(map(str, non)))
   kw = re.findall(r'&lt;Keywords&gt;(.*?)&lt;/Keywords&gt;',data,re.DOTALL)
   kw1 = "".join(map(str, kw)).replace('\n','')
   pe = np.array(re.findall(r'&lt;Primitive Exponents&gt;(.*?)&lt;/Primitive Exponents&gt;',data,re.DOTALL))
  </code></pre>
  
  <p>Any ideas on how to approach this problem/modify my code to extract the matrix as is (a 3x3 array)?</p>
  
  <p>Thank you! </p>