title: Python if function across a vector
body: <p>I'm new to Python and trying to work out how to do the following.</p>
  
  <h2>I have a data array, X, which looks something like:</h2>
  
  <pre><code>X = [ 1 2 3
  
        4 5 6 
  
        7 8 9 
  
        10 11 12];
  </code></pre>
  
  <p>Such that the first column <code>X[0]</code> is,</p>
  
  <pre><code>X[0] =[1
         4
         7
         10];
  </code></pre>
  
  <p>the second column <code>X[1]</code> is,</p>
  
  <pre><code>X[1] =[2
         5
         8
         11];
  </code></pre>
  
  <p>and third column <code>X[2]</code> is,</p>
  
  <pre><code>X[2] =[3
         6
         9
         12];
  </code></pre>
  
  <p>What I want to do is generate a single random number, <code>k</code>, and if any of the values in the first column <code>X[0]</code> are greater than <code>k</code> I want to multiply the third column by a function (<code>2*X[0]</code>), and if any of the values are less than <code>k</code> I want to multiply by a different function (<code>2*k</code>).</p>
  
  <p>So if <code>k=2</code>, the third column becomes:
  and third column <code>X[2]</code> is,</p>
  
  <pre><code>X[2] =[3*2*k
         6*2*X[0,1]
         9*2*X[0,2]
         12*2*X[0,3] ];
  </code></pre>
  
  <p>Is there a succinct way to do this?</p>