title: Python - slice array until certain condition is met
body: <p>I need to slice an array from a given index until a certain condition is met.</p>
  
  <pre><code>&gt;&gt;&gt; a = numpy.zeros((10), dtype='|S1')
  &gt;&gt;&gt; a[2] = 'A'
  &gt;&gt;&gt; a[4] = 'X'
  &gt;&gt;&gt; a[8] = 'B'
  &gt;&gt;&gt; a
  array(['', '', 'A', '', 'X', '', '', '', 'B', ''], dtype='|S1')
  </code></pre>
  
  <p>For instance, for the above array I want a subset from a given index until first non-zero values in both directions. For example, for index values 2, 4, 8 the results would be:</p>
  
  <pre><code>['', '', A, '']      # 2
  ['', X, '', '', '']  # 4
  ['', '', '', B, '']  # 8
  </code></pre>
  
  <p>Any suggestions on the simplest way to do this using the numpy API? Learning python and numpy, would appreciate any help. Thanks!</p>