<font size=2 face="sans-serif">I have several functions like the example
below that I would like to make compatible with array inputs. The problem
is the conditional statements give a <i>ValueError: The truth value of
an array with more than one element is ambiguous. Use a.any() or a.all()</i>.
I can use numpy.vectorize, but if possible I'd prefer to rewrite the function.
Does anyone have any advice the best way to modify the code to accept array
inputs? Thanks in advance for any assistance.</font>
<br>
<br>
<br><tt><font size=2 color=#000080>NAN = float('nan')</font></tt>
<br>
<br><tt><font size=2 color=#000080>def air_gamma(t, far=0.0):</font></tt>
<br><tt><font size=2 color=#000080>    """</font></tt>
<br><tt><font size=2 color=#000080>    Specific heat ratio (gamma)
of Air/JP8</font></tt>
<br><tt><font size=2 color=#000080>    t - static temperature,
Rankine</font></tt>
<br><tt><font size=2 color=#000080>    [far] - fuel air ratio
[- defaults to 0.0 (dry air)]</font></tt>
<br><tt><font size=2 color=#000080>    air_gamma - specific heat
ratio</font></tt>
<br><tt><font size=2 color=#000080>    """</font></tt>
<br><tt><font size=2 color=#000080>    if far < 0.:</font></tt>
<br><tt><font size=2 color=#000080>        return NAN</font></tt>
<br><tt><font size=2 color=#000080>    elif far < 0.005:</font></tt>
<br><tt><font size=2 color=#000080>        if t <
379. or t > 4731.:</font></tt>
<br><tt><font size=2 color=#000080>           
return NAN</font></tt>
<br><tt><font size=2 color=#000080>        else:</font></tt>
<br><tt><font size=2 color=#000080>           
air_gamma = -3.472487e-22 * t ** 6. + 6.218811e-18 * t ** 5. - 4.428098e-14
* t ** 4. + 1.569889e-10 * t ** 3. - 0.0000002753524 * t ** 2. + 0.0001684666
* t + 1.368652</font></tt>
<br><tt><font size=2 color=#000080>    elif far < 0.069:</font></tt>
<br><tt><font size=2 color=#000080>        if t <
699. or t > 4731.:</font></tt>
<br><tt><font size=2 color=#000080>           
return NAN</font></tt>
<br><tt><font size=2 color=#000080>        else:</font></tt>
<br><tt><font size=2 color=#000080>           
a6 = 4.114808e-20 * far ** 3. - 1.644588e-20 * far ** 2. + 3.103507e-21
* far - 3.391308e-22</font></tt>
<br><tt><font size=2 color=#000080>           
a5 = -6.819015e-16 * far ** 3. + 2.773945e-16 * far ** 2. - 5.469399e-17
* far + 6.058125e-18</font></tt>
<br><tt><font size=2 color=#000080>           
a4 = 4.684637e-12 * far ** 3. - 1.887227e-12 * far ** 2. + 3.865306e-13
* far - 4.302534e-14</font></tt>
<br><tt><font size=2 color=#000080>           
a3 = -0.00000001700602 * far ** 3. + 0.000000006593809 * far ** 2. - 0.000000001392629
* far + 1.520583e-10</font></tt>
<br><tt><font size=2 color=#000080>           
a2 = 0.00003431136 * far ** 3. - 0.00001248285 * far ** 2. + 0.000002688007
* far - 0.0000002651616</font></tt>
<br><tt><font size=2 color=#000080>           
a1 = -0.03792449 * far ** 3. + 0.01261025 * far ** 2. - 0.002676877 * far
+ 0.0001580424</font></tt>
<br><tt><font size=2 color=#000080>           
a0 = 13.65379 * far ** 3. - 3.311225 * far ** 2. + 0.3573201 * far + 1.372714</font></tt>
<br><tt><font size=2 color=#000080>           
air_gamma = a6 * t ** 6. + a5 * t ** 5. + a4 * t ** 4. + a3 * t ** 3. +
a2 * t ** 2. + a1 * t + a0</font></tt>
<br><tt><font size=2 color=#000080>    elif far >= 0.069:</font></tt>
<br><tt><font size=2 color=#000080>        return NAN</font></tt>
<br><tt><font size=2 color=#000080>    else:</font></tt>
<br><tt><font size=2 color=#000080>        return NAN</font></tt>
<br><tt><font size=2 color=#000080>    return air_gamma</font></tt>
<br>
<br><font size=2 face="Century Gothic">David Parker <br>
Chromalloy - TDAG</font>