title: Finding the index of elements based on a condition using python list comprehension
body: <p>The following Python code appears to be very long winded when coming from a Matlab background</p>
  
  <pre><code>&gt;&gt;&gt; a = [1, 2, 3, 1, 2, 3]
  &gt;&gt;&gt; [index for index,value in enumerate(a) if value &gt; 2]
  [2, 5]
  </code></pre>
  
  <p>When in Matlab I can write:</p>
  
  <pre><code>&gt;&gt; a = [1, 2, 3, 1, 2, 3];
  &gt;&gt; find(a&gt;2)
  ans =
       3     6
  </code></pre>
  
  <p>Is there a short hand method of writing this in Python, or do I just stick with the long version?</p>
  
  <hr>
  
  <p>Thank you for all the suggestions and explanation of the rationale for Python's syntax.</p>
  
  <p>After finding the following on the numpy website, I think I have found a solution I like:</p>
  
  <p><a href="http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays" rel="noreferrer">http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays</a></p>
  
  <p>Applying the information from that website to my problem above, would give the following:</p>
  
  <pre><code>&gt;&gt;&gt; from numpy import array
  &gt;&gt;&gt; a = array([1, 2, 3, 1, 2, 3])
  &gt;&gt;&gt; b = a&gt;2 
  array([False, False, True, False, False, True], dtype=bool)
  &gt;&gt;&gt; r = array(range(len(b)))
  &gt;&gt;&gt; r(b)
  [2, 5]
  </code></pre>
  
  <p>The following should then work (but I haven't got a Python interpreter on hand to test it):</p>
  
  <pre><code>class my_array(numpy.array):
      def find(self, b):
          r = array(range(len(b)))
          return r(b)
  
  
  &gt;&gt;&gt; a = my_array([1, 2, 3, 1, 2, 3])
  &gt;&gt;&gt; a.find(a&gt;2)
  [2, 5]
  </code></pre>