diff options
author | Pauli Virtanen <pav@iki.fi> | 2009-01-17 21:24:13 +0000 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2009-01-17 21:24:13 +0000 |
commit | 9efaa09baca5ce2d64447bdcc91556227ab717c2 (patch) | |
tree | ea5d43b99c8cae7ea120e1234bb6e99b2e96bade /numpy/lib/function_base.py | |
parent | 4b9c0f2208305046275c74ec1c9d6fda8af1f5bb (diff) | |
download | numpy-9efaa09baca5ce2d64447bdcc91556227ab717c2.tar.gz |
Make `trapz` accept 1-D `x` parameter for n-d `y`, even if axis != -1.
Additional tests included.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 425960639..269a97721 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -2818,9 +2818,9 @@ def trapz(y, x=None, dx=1.0, axis=-1): y : array_like Input array to integrate. x : array_like, optional - If `x` is None, then spacing between all `y` elements is 1. + If `x` is None, then spacing between all `y` elements is `dx`. dx : scalar, optional - If `x` is None, spacing given by `dx` is assumed. + If `x` is None, spacing given by `dx` is assumed. Default is 1. axis : int, optional Specify the axis. @@ -2836,7 +2836,15 @@ def trapz(y, x=None, dx=1.0, axis=-1): if x is None: d = dx else: - d = diff(x,axis=axis) + x = asarray(x) + if x.ndim == 1: + d = diff(x) + # reshape to correct shape + shape = [1]*y.ndim + shape[axis] = d.shape[0] + d = d.reshape(shape) + else: + d = diff(x, axis=axis) nd = len(y.shape) slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd |