summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2009-05-20 21:50:09 +0000
committerPauli Virtanen <pav@iki.fi>2009-05-20 21:50:09 +0000
commitd3133f1ed2d3c2e56853d14a5b3e5e1f2cff11e2 (patch)
tree7590c4f73a0a4e2009a8de860f49699e05bd5a94 /numpy
parent260728f7a0010f717a246be1b199b93ea89c02fc (diff)
downloadnumpy-d3133f1ed2d3c2e56853d14a5b3e5e1f2cff11e2.tar.gz
Docstring fixes: make some examples to work properly
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/function_base.py43
-rw-r--r--numpy/random/mtrand/mtrand.pyx11
2 files changed, 32 insertions, 22 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 00dc92f1f..1b84c864d 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -2070,7 +2070,7 @@ def blackman(M):
Plot the window and the frequency response:
- >>> from numpy import clip, log10, array, bartlett
+ >>> from numpy import clip, log10, array, bartlett, linspace
>>> from scipy.fftpack import fft, fftshift
>>> import matplotlib.pyplot as plt
@@ -2080,17 +2080,19 @@ def blackman(M):
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("Sample")
>>> plt.show()
-
+
+ >>> plt.figure()
>>> A = fft(window, 2048) / 25.5
>>> mag = abs(fftshift(A))
>>> freq = linspace(-0.5,0.5,len(A))
>>> response = 20*log10(mag)
>>> response = clip(response,-100,100)
>>> plt.plot(freq, response)
- >>> plt.title("Frequency response of Bartlett window")
+ >>> plt.title("Frequency response of Blackman window")
>>> plt.ylabel("Magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")
- >>> plt.axis('tight'); plt.show()
+ >>> plt.axis('tight')
+ >>> plt.show()
"""
if M < 1:
@@ -2167,8 +2169,8 @@ def bartlett(M):
Plot the window and its frequency response (requires SciPy and matplotlib):
- >>> from numpy import clip, log10, array, bartlett
- >>> from numpy.fft import fft
+ >>> from numpy import clip, log10, array, bartlett, linspace
+ >>> from numpy.fft import fft, fftshift
>>> import matplotlib.pyplot as plt
>>> window = bartlett(51)
@@ -2177,7 +2179,8 @@ def bartlett(M):
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("Sample")
>>> plt.show()
-
+
+ >>> plt.figure()
>>> A = fft(window, 2048) / 25.5
>>> mag = abs(fftshift(A))
>>> freq = linspace(-0.5,0.5,len(A))
@@ -2187,7 +2190,8 @@ def bartlett(M):
>>> plt.title("Frequency response of Bartlett window")
>>> plt.ylabel("Magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")
- >>> plt.axis('tight'); plt.show()
+ >>> plt.axis('tight')
+ >>> plt.show()
"""
if M < 1:
@@ -2261,23 +2265,24 @@ def hanning(M):
>>> import matplotlib.pyplot as plt
>>> window = np.hanning(51)
- >>> plt.subplot(121)
>>> plt.plot(window)
>>> plt.title("Hann window")
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("Sample")
+ >>> plt.show()
+ >>> plt.figure()
>>> A = fft(window, 2048) / 25.5
>>> mag = abs(fftshift(A))
>>> freq = np.linspace(-0.5,0.5,len(A))
>>> response = 20*np.log10(mag)
>>> response = np.clip(response,-100,100)
- >>> plt.subplot(122)
>>> plt.plot(freq, response)
>>> plt.title("Frequency response of the Hann window")
>>> plt.ylabel("Magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")
- >>> plt.axis('tight'); plt.show()
+ >>> plt.axis('tight')
+ >>> plt.show()
"""
if M < 1:
@@ -2346,7 +2351,7 @@ def hamming(M):
Plot the window and the frequency response:
- >>> from numpy import clip, log10, array, hamming
+ >>> from numpy import clip, log10, array, hamming, linspace
>>> from scipy.fftpack import fft, fftshift
>>> import matplotlib.pyplot as plt
@@ -2357,6 +2362,7 @@ def hamming(M):
>>> plt.xlabel("Sample")
>>> plt.show()
+ >>> plt.figure()
>>> A = fft(window, 2048) / 25.5
>>> mag = abs(fftshift(A))
>>> freq = linspace(-0.5,0.5,len(A))
@@ -2366,7 +2372,8 @@ def hamming(M):
>>> plt.title("Frequency response of Hamming window")
>>> plt.ylabel("Magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")
- >>> plt.axis('tight'); plt.show()
+ >>> plt.axis('tight')
+ >>> plt.show()
"""
if M < 1:
@@ -2591,7 +2598,7 @@ def kaiser(M,beta):
Plot the window and the frequency response:
- >>> from numpy import clip, log10, array, kaiser
+ >>> from numpy import clip, log10, array, kaiser, linspace
>>> from scipy.fftpack import fft, fftshift
>>> import matplotlib.pyplot as plt
@@ -2602,6 +2609,7 @@ def kaiser(M,beta):
>>> plt.xlabel("Sample")
>>> plt.show()
+ >>> plt.figure()
>>> A = fft(window, 2048) / 25.5
>>> mag = abs(fftshift(A))
>>> freq = linspace(-0.5,0.5,len(A))
@@ -2611,7 +2619,8 @@ def kaiser(M,beta):
>>> plt.title("Frequency response of Kaiser window")
>>> plt.ylabel("Magnitude [dB]")
>>> plt.xlabel("Normalized frequency [cycles per sample]")
- >>> plt.axis('tight'); plt.show()
+ >>> plt.axis('tight')
+ >>> plt.show()
"""
from numpy.dual import i0
@@ -2676,7 +2685,7 @@ def sinc(x):
-4.92362781e-02, -3.89804309e-17])
>>> import matplotlib.pyplot as plt
- >>> plt.plot(x, sinc(x))
+ >>> plt.plot(x, np.sinc(x))
>>> plt.title("Sinc Function")
>>> plt.ylabel("Amplitude")
>>> plt.xlabel("X")
@@ -2686,7 +2695,7 @@ def sinc(x):
>>> x = np.arange(-200., 201.)/50.
>>> xx = np.outer(x, x)
- >>> plt.imshow(sinc(xx))
+ >>> plt.imshow(np.sinc(xx))
"""
y = pi* where(x == 0, 1.0e-20, x)
diff --git a/numpy/random/mtrand/mtrand.pyx b/numpy/random/mtrand/mtrand.pyx
index b3b676b9c..2bc2652fe 100644
--- a/numpy/random/mtrand/mtrand.pyx
+++ b/numpy/random/mtrand/mtrand.pyx
@@ -1279,8 +1279,8 @@ cdef class RandomState:
>>> import matplotlib.pyplot as plt
>>> import scipy.special as sps
>>> count, bins, ignored = plt.hist(s, 50, normed=True)
- >>> y = bins**(shape-1)*((exp(-bins/scale))/\\
- (sps.gamma(shape)*scale**shape))
+ >>> y = bins**(shape-1)*(exp(-bins/scale) /
+ ... (sps.gamma(shape)*scale**shape))
>>> plt.plot(bins, y, linewidth=2, color='r')
>>> plt.show()
@@ -1672,8 +1672,8 @@ cdef class RandomState:
>>> import matplotlib.pyplot as plt
>>> import scipy.special as sps
>>> count, bins, ignored = plt.hist(s, 50, normed=True)
- >>> x = arange(-pi, pi, 2*pi/50.)
- >>> y = -np.exp(kappa*np.cos(x-mu))/(2*pi*sps.jn(0,kappa))
+ >>> x = np.arange(-np.pi, np.pi, 2*np.pi/50.)
+ >>> y = -np.exp(kappa*np.cos(x-mu))/(2*np.pi*sps.jn(0,kappa))
>>> plt.plot(x, y/max(y), linewidth=2, color='r')
>>> plt.show()
@@ -1858,6 +1858,7 @@ cdef class RandomState:
the probability density function:
>>> import matplotlib.pyplot as plt
+ >>> x = np.arange(1,100.)/50.
>>> def weib(x,n,a):
... return (a / n) * (x / n)**(a - 1) * np.exp(-(x / n)**a)
@@ -2619,7 +2620,7 @@ cdef class RandomState:
>>> import scipy.special as sps
Truncate s values at 50 so plot is interesting
>>> count, bins, ignored = plt.hist(s[s<50], 50, normed=True)
- >>> x = arange(1., 50.)
+ >>> x = np.arange(1., 50.)
>>> y = x**(-a)/sps.zetac(a)
>>> plt.plot(x, y/max(y), linewidth=2, color='r')
>>> plt.show()