ML Foundations
Understand coordinate order in NumPy trapezoidal integration
Explain a negative signed area and keep paired coordinates aligned when sorting samples.

Evidence and testing
Review record: Tensor Almanac automated evidence gate (no independent human review). Example versions, recorded outputs and limitations appear below.
Integration follows the supplied path
NumPy trapezoid uses the supplied x coordinates in sequence; it does not sort them. Integrating along decreasing coordinates reverses the direction of integration, so a positive curve can produce a negative signed result. [1]
That sign is a property of the ordered path. Before changing it, decide whether the sequence represents a traversal whose direction matters or a set of unordered samples of a function. [1]
References: [1]
Reverse and restore paired samples
Run python examples/numpy_trapezoid_order.py. Three ascending coordinates and their paired values produce four. Reversing both arrays preserves the same points but reverses traversal, producing minus four. [1]
If the desired contract is increasing x, argsort supplies an ordering that must be applied to both x and y. Sorting only the coordinates would pair values with the wrong positions. The example checks that sorting the reversed pairs restores the original result. [2]
Executed with Python 3.12.14; stdout and checksum recorded in private evidence.
import numpy as np
x = np.array([0.0, 1.0, 2.0])
y = np.array([0.0, 2.0, 4.0])
forward = np.trapezoid(y, x)
reverse = np.trapezoid(y[::-1], x[::-1])
order = np.argsort(x[::-1])
restored = np.trapezoid(y[::-1][order], x[::-1][order])
assert forward == 4.0 and reverse == -4.0 and restored == 4.0
print("forward:", float(forward))
print("reversed pairs:", float(reverse))
print("paired sort:", float(restored))
Recorded output
forward: 4.0 reversed pairs: -4.0 paired sort: 4.0
Decide what the area means
Do not automatically sort a path where traversal carries meaning, such as an intentionally ordered parametric curve. Sorting changes the path and can change the quantity being integrated. NumPy accepts the coordinates in the sequence supplied. [1]
This example uses distinct one-dimensional coordinates and NumPy trapezoid, available from NumPy 2.0. It demonstrates an ordering issue only; a particular evaluation metric may require additional definitions and validation. [1]
References: [1]