title: Array indexing by array-value and array-value dependant operation
body: <p>I'm developing a finite-volume heat-transfer model in python with numpy. I've got a number of cells stacked vertically (for the next year a transfer to a 3d-model is planned) with each having a different temperature.</p>
  
  <hr>
  
  <p>*To calculate the heat transfer between the cells, I need the thermal conductivity depending on the cell-temperature.
  The thermal conductivity with its corresponding temperature (in degree Celsius) is stored in matrix <code>TC</code>, the cell-temperatures (in degree Celsius) are stored in vector (in the future in a matrix) <code>T_Cell</code>. These arrays look like:</p>
  
  <pre><code>TC = numpy.array([[0,569],[1,574],[2,582],[3,590],[4,598],[5,606],[6,613],[7,620]])
  T_Cell  = numpy.array([[7],[5],[5],[4],[4],[3],[1],[0],[0]])
  </code></pre>
  
  <p>The temperatures in <code>TC</code> correspond to their row-index, so that accessing the thermal conductivity for example for a cell temperature of <code>T_Cell=5</code> can be done by indexing with the temperature (the value stored in T_Cell). Here shown for the cell with Index 2:  </p>
  
  <pre><code>TC_Cell = TC[numpy.round(T_Cell[2]),1]
  </code></pre>
  
  <p>Resulting in <code>TC_Cell = 606</code>.
  Is there an array-operation which allows me to get the cell's thermal conductivity (depending only on the cell's temperature) in an array with the same shape as <code>T_Cell</code>? For example with the arrays of <code>TC</code> and <code>T_Cell</code> as shown above:  </p>
  
  <pre><code>TC_Cell = TC[T_Cell, 1]
  </code></pre>
  
  <p>So that the result for TC_Cell looks like:</p>
  
  <p><code>TC_Cell = array([[620],
         [606],
         [606],
         [598],
         [598],
         [590],
         [574],
         [569],
         [569]])</code></p>
  
  <p>Interpolation is NOT needed as I already interpolated the values in TC to a satisfying degree (not shown here to keep it clean, values in the array are also simplified and physically not correct).*</p>
  
  <p><strong>I really don't know why, but suddenly it is working exactly like shown in my example... Maybe I had a typo somewhere in my code... :-/ Though my second question remains unresolved.</strong></p>
  
  <hr>
  
  <p>My second question is:
  I've got a differential equation with a solution which changes depending if one argument is zero or non-zero. This argument is depending on the cell, so it might be</p>
  
  <pre><code>Arg = numpy.array([[0.12],[0.9],[0],[0],[0.2]])
  </code></pre>
  
  <p>Currently my way to decide which solution to use is to run a for-loop over the <code>Arg</code>-vector (in the future: 3d-array) and to check if a cell is <code>0</code>. Like:</p>
  
  <pre><code>a=1
  c=2
  d=3
  for cell in range(numpy.size(Arg, 0)):
      if Arg[cell, 0] != 0:
          # Solution1:
          Solution[cell] = (a / Arg[cell] + c) * numpy.e**(Arg[cell] * d) - (a / Arg[cell])
      elif Arg[cell, 0] == 0:
          # Solution2:
          Solution[cell] = a * d + c
  </code></pre>
  
  <p>With the result:</p>
  
  <pre><code>Solution = array([[  6.47773728],
     [ 45.18138759],
     [  5.        ],
     [  5.        ],
     [  7.7548316 ]])
  </code></pre>
  
  <p>Is there an array operation with which I can avoid using the for-loop?<br>
  <strong>And to avoid further confusion due to missing information: <code>a</code> is also an array of the same size/shape as <code>Arg</code>:</strong></p>
  
  <pre><code>a = numpy.array([[1],[1],[1],[1],[1]])
  </code></pre>
  
  <p>(And the values are not necessarily <code>1</code>!)</p>
  
  <p>Thanks for your help in advance!</p>