diff options
author | Ralf Gommers <ralf.gommers@gmail.com> | 2019-04-14 23:02:20 +0200 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@gmail.com> | 2019-04-14 23:09:35 +0200 |
commit | 418e3bf0789dcd7d064de55a266b186d4ab42774 (patch) | |
tree | 2eff356062ff9b523e748a452f6c515bfbecb12e | |
parent | 5343bc84bbbd36df73b4678d5f58c2cbcc1dda85 (diff) | |
download | numpy-418e3bf0789dcd7d064de55a266b186d4ab42774.tar.gz |
DOC: fix 4 remaining doc build warnings.
2 for polyfit rankwarning, 2 for divide by zero in log10.
-rw-r--r-- | numpy/lib/function_base.py | 62 | ||||
-rw-r--r-- | numpy/lib/polynomial.py | 6 |
2 files changed, 35 insertions, 33 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index fb40ef927..dad2e3bcd 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -377,7 +377,7 @@ def average(a, axis=None, weights=None, returned=False): Traceback (most recent call last): ... TypeError: Axis must be specified when shapes of a and weights differ. - + >>> a = np.ones(5, dtype=np.float128) >>> w = np.ones(5, dtype=np.complex64) >>> avg = np.average(a, weights=w) @@ -1431,7 +1431,7 @@ def angle(z, deg=False): angle : ndarray or scalar The counterclockwise angle from the positive real axis on the complex plane, with dtype as numpy.float64. - + ..versionchanged:: 1.16.0 This function works on subclasses of ndarray like `ma.array`. @@ -1929,6 +1929,30 @@ class vectorize(object): vectorized : callable Vectorized function. + See Also + -------- + frompyfunc : Takes an arbitrary Python function and returns a ufunc + + Notes + ----- + The `vectorize` function is provided primarily for convenience, not for + performance. The implementation is essentially a for loop. + + If `otypes` is not specified, then a call to the function with the + first argument will be used to determine the number of outputs. The + results of this call will be cached if `cache` is `True` to prevent + calling the function twice. However, to implement the cache, the + original function must be wrapped which will slow down subsequent + calls, so only do this if your function is expensive. + + The new keyword argument interface and `excluded` argument support + further degrades performance. + + References + ---------- + .. [1] NumPy Reference, section `Generalized Universal Function API + <https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html>`_. + Examples -------- >>> def myfunc(a, b): @@ -1988,8 +2012,8 @@ class vectorize(object): >>> import scipy.stats >>> pearsonr = np.vectorize(scipy.stats.pearsonr, - ... signature='(n),(n)->(),()') - >>> pearsonr([[0, 1, 2, 3]], [[1, 2, 3, 4], [4, 3, 2, 1]]) + ... signature='(n),(n)->(),()') + >>> pearsonr([[0, 1, 2, 3]], [[1, 2, 3, 4], [4, 3, 2, 1]]) (array([ 1., -1.]), array([ 0., 0.])) Or for a vectorized convolution: @@ -2001,31 +2025,7 @@ class vectorize(object): [0., 0., 1., 2., 1., 0.], [0., 0., 0., 1., 2., 1.]]) - See Also - -------- - frompyfunc : Takes an arbitrary Python function and returns a ufunc - - Notes - ----- - The `vectorize` function is provided primarily for convenience, not for - performance. The implementation is essentially a for loop. - - If `otypes` is not specified, then a call to the function with the - first argument will be used to determine the number of outputs. The - results of this call will be cached if `cache` is `True` to prevent - calling the function twice. However, to implement the cache, the - original function must be wrapped which will slow down subsequent - calls, so only do this if your function is expensive. - - The new keyword argument interface and `excluded` argument support - further degrades performance. - - References - ---------- - .. [1] NumPy Reference, section `Generalized Universal Function API - <https://docs.scipy.org/doc/numpy/reference/c-api.generalized-ufuncs.html>`_. """ - def __init__(self, pyfunc, otypes=None, doc=None, excluded=None, cache=False, signature=None): self.pyfunc = pyfunc @@ -2602,7 +2602,7 @@ def blackman(M): Plot the window and the frequency response: >>> from numpy.fft import fft, fftshift - >>> window = np.blackman(51) + >>> window = np.blackman(51) + 1e-10 # eps shift to avoid division by zero >>> plt.plot(window) [<matplotlib.lines.Line2D object at 0x...>] >>> plt.title("Blackman window") @@ -2709,7 +2709,7 @@ def bartlett(M): Plot the window and its frequency response (requires SciPy and matplotlib): >>> from numpy.fft import fft, fftshift - >>> window = np.bartlett(51) + >>> window = np.bartlett(51) + 1e-10 # eps shift to avoid division by zero >>> plt.plot(window) [<matplotlib.lines.Line2D object at 0x...>] >>> plt.title("Bartlett window") @@ -2810,7 +2810,7 @@ def hanning(M): >>> import matplotlib.pyplot as plt >>> from numpy.fft import fft, fftshift - >>> window = np.hanning(51) + >>> window = np.hanning(51) + 1e-10 # eps shift to avoid division by zero >>> plt.plot(window) [<matplotlib.lines.Line2D object at 0x...>] >>> plt.title("Hann window") diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index 62f96f773..8c6f69cb0 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -548,6 +548,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False): Examples -------- + >>> import warnings >>> x = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0]) >>> y = np.array([0.0, 0.8, 0.9, 0.1, -0.8, -1.0]) >>> z = np.polyfit(x, y, 3) @@ -566,9 +567,10 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False): High-order polynomials may oscillate wildly: - >>> p30 = np.poly1d(np.polyfit(x, y, 30)) + >>> with warnings.catch_warnings(): + ... warnings.simplefilter('ignore', np.RankWarning) + ... p30 = np.poly1d(np.polyfit(x, y, 30)) ... - >>> # RankWarning: Polyfit may be poorly conditioned... >>> p30(4) -0.80000000000000204 # may vary >>> p30(5) |