<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Trapz finds the area under a one-to-one association of y values with x<br>
values.  If y(x) > 0, then the area bounded by [a, b] between y(x) and<br>
x=0 should always be positive.  </blockquote><div><br></div><div>You could write a trapz that does that, however np.trapz finds the integral from a to b of y using the sampled data you provide.  The "from" in there is important.  Since we are integrating samples, the a and b are essentially the first and last points of the x input. Since a is x[0] and b is x[-1], the x array is defining the path along which to integrate. <br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The core property you have referenced<br>
above is the very property that should be used in order to achieve the<br>
equivalence with integrating along a negative path.  Maintaining this<br>
separation preserves the equivalence of<br>
np.trapz(y,x) == np.trapz(y[::-1], x[::-1]), which I believe is an<br>
equivalence that should hold true.<br></blockquote><div><br></div><div>This equivalence is false.  For instance both of these results are correct.  Would they still be with your changes?<br>

<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,128)">In [</span><span style="font-weight:600;color:rgb(0,0,128)">46</span><span style="color:rgb(0,0,128)">]:</span> x = np.exp(1j*np.pi*np.linspace(0,1,100))</p>
<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,128)">In [</span><span style="font-weight:600;color:rgb(0,0,128)">47</span><span style="color:rgb(0,0,128)">]:</span> z = 1/x</p>
<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,128)">In [</span><span style="font-weight:600;color:rgb(0,0,128)">48</span><span style="color:rgb(0,0,128)">]:</span> np.trapz(z, x)</p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(139,0,0)">Out[</span><span style="font-weight:600;color:rgb(139,0,0)">48</span><span style="color:rgb(139,0,0)">]:</span> (1.3244509217643717e-18+3.1410654163086975j)</p>
<p style="margin:0px;text-indent:0px"><br></p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(0,0,128)">In [</span><span style="font-weight:600;color:rgb(0,0,128)">49</span><span style="color:rgb(0,0,128)">]:</span> np.trapz(z[::-1], x[::-1])</p>
<p style="margin:0px;text-indent:0px"><span style="color:rgb(139,0,0)">Out[</span><span style="font-weight:600;color:rgb(139,0,0)">49</span><span style="color:rgb(139,0,0)">]:</span> (-1.3244509217643594e-18-3.1410654163086971j)</p><br><br></div><div>Eric</div></div><br></div></div>