[SciPy-Dev] Code review for trapz update

fizyxnrd fizyxnrd at gmail.com
Wed Mar 11 08:48:39 EDT 2015


>On Wed, Mar 11, 2015 at 12:11 AM, Sturla Molden <sturla.molden <at> 
gmail.com> wrote:
>On 11/03/15 00:23, fizyxnrd wrote:

>> It appears that there is more use for the current form than I have 
come
>> across with my adventures in positive-definite quantities.  Is there
>> room for a keyword e.g., unsorted ( so that the call is trapz(y, 
x=None,
>> dx = 1.0, axis=-1, unsorted=False) where if unsorted is set to True, 
the
>> data is automatically sorted before integration?

>I think a numerical integral routine should only return an 
approximation
>to the integral. If you sort the data the trapz function is no longer
>returning an approximation to the integral.

>Sturla

I was not clear in what I meant should be sorted.  I am envisioning 
something like

x 
= np.random.rand(100)
y = np.random.rand(100)

# Assume that x should be an ordered quantity
idx = np.argsort(x)

result = np.trapz(y[idx], x[idx])

The intent is not to sort the y values by value, only to assume that 
there is no meaningful path information in the x values, and so to sort 
them so that only the total area under y is computed, without regard to 
direction.





More information about the SciPy-Dev mailing list