title: Functional masking of numpy string array in Python
body: <p>I'm trying to extract either the first (or only) <strong>floating point</strong> or <strong>integer</strong> from strings like these:</p>
  
  <pre><code>str1 = np.asarray('92834.1alksjdhaklsjh')
  str2 = np.asarray'-987___-')
  str3 = np.asarray'-234234.alskjhdasd')
  </code></pre>
  
  <p>where, if parsed correctly, we should get</p>
  
  <pre><code>var1 = 92834.1   #float
  var2 = -987      #int 
  var3 = -234234.0 #float
  </code></pre>
  
  <p>Using the "masking" property of numpy arrays I come up with something like for any of the <code>str_</code> variables, e.g.:</p>
  
  <pre><code>&gt;&gt; ma1 = np.asarray([not str.isalpha(c) for c in str1.tostring()],dtype=bool)
  
  array([ True,  True,  True,  True,  True,  True,  True, False, False,
       False, False, False, False, False, False, False, False, False,
       False, False], dtype=bool)
  
  &gt;&gt; str1[ma1]
  
  IndexError: too many indeces for array 
  </code></pre>
  
  <p>Now I've read just about everything I can find about indexing using boolean arrays; but I can't get it to work.</p>
  
  <p>It's simple enough that I don't think hunkering down to figure out a regex for is worth it, but complex enough that it's been giving me trouble.</p>