Skip to content

Commit 9448ff2

Browse files
committed
Merge pull request matplotlib#1183 from NelleV/mlab_fixes
FIX undefined elements were used at several places in the mlab module
2 parents 19cbb14 + 5d67cef commit 9448ff2

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

lib/matplotlib/mlab.py

+12-21
Original file line numberDiff line numberDiff line change
@@ -699,16 +699,15 @@ def entropy(y, bins):
699699
x = mu + sigma * randn(200000)
700700
Sanalytic = 0.5 * ( 1.0 + log(2*pi*sigma**2.0) )
701701
"""
702-
n,bins = np.histogram(y, bins)
702+
n, bins = np.histogram(y, bins)
703703
n = n.astype(np.float_)
704704

705705
n = np.take(n, np.nonzero(n)[0]) # get the positive
706706

707707
p = np.divide(n, len(y))
708708

709-
delta = bins[1]-bins[0]
710-
S = -1.0*np.sum(p*log(p)) + log(delta)
711-
#S = -1.0*np.sum(p*log(p))
709+
delta = bins[1] - bins[0]
710+
S = -1.0 * np.sum(p * np.log(p)) + np.log(delta)
712711
return S
713712

714713
def normpdf(x, *args):
@@ -722,22 +721,20 @@ def levypdf(x, gamma, alpha):
722721

723722
N = len(x)
724723

725-
if N%2 != 0:
724+
if N % 2 != 0:
726725
raise ValueError('x must be an event length array; try\n' + \
727726
'x = np.linspace(minx, maxx, N), where N is even')
728727

728+
dx = x[1] - x[0]
729729

730-
dx = x[1]-x[0]
730+
f = 1/(N*dx)*np.arange(-N / 2, N / 2, np.float_)
731731

732+
ind = np.concatenate([np.arange(N / 2, N, int),
733+
np.arange(0, N / 2, int)])
734+
df = f[1] - f[0]
735+
cfl = np.exp(-gamma * np.absolute(2 * np.pi * f) ** alpha)
732736

733-
f = 1/(N*dx)*np.arange(-N/2, N/2, np.float_)
734-
735-
ind = np.concatenate([np.arange(N/2, N, int),
736-
np.arange(0, N/2, int)])
737-
df = f[1]-f[0]
738-
cfl = exp(-gamma*np.absolute(2*pi*f)**alpha)
739-
740-
px = np.fft.fft(np.take(cfl,ind)*df).astype(np.float_)
737+
px = np.fft.fft(np.take(cfl, ind) * df).astype(np.float_)
741738
return np.take(px, ind)
742739

743740

@@ -1458,7 +1455,6 @@ def splitfunc(x):
14581455
else:
14591456
row = [converterseq[j](val)
14601457
for j,val in enumerate(splitfunc(line))]
1461-
thisLen = len(row)
14621458
X.append(row)
14631459

14641460
X = np.array(X, dtype)
@@ -1511,7 +1507,6 @@ def splitfunc(x):
15111507
15121508
"""
15131509

1514-
import operator
15151510
import math
15161511

15171512

@@ -1533,7 +1528,7 @@ def exp_safe(x):
15331528
"""
15341529

15351530
if type(x) is np.ndarray:
1536-
return exp(np.clip(x,exp_safe_MIN,exp_safe_MAX))
1531+
return np.exp(np.clip(x,exp_safe_MIN,exp_safe_MAX))
15371532
else:
15381533
return math.exp(x)
15391534

@@ -1817,7 +1812,6 @@ def rec_drop_fields(rec, names):
18171812
"""
18181813

18191814
names = set(names)
1820-
Nr = len(rec)
18211815

18221816
newdtype = np.dtype([(name, rec.dtype[name]) for name in rec.dtype.names
18231817
if name not in names])
@@ -2146,8 +2140,6 @@ def csv2rec(fname, comments='#', skiprows=0, checkrows=0, delimiter=',',
21462140

21472141
import dateutil.parser
21482142
import datetime
2149-
parsedate = dateutil.parser.parse
2150-
21512143

21522144
fh = cbook.to_filehandle(fname)
21532145

@@ -2938,7 +2930,6 @@ def stineman_interp(xi,x,y,yp=None):
29382930
x=np.asarray(x, np.float_)
29392931
y=np.asarray(y, np.float_)
29402932
assert x.shape == y.shape
2941-
N=len(y)
29422933

29432934
if yp is None:
29442935
yp = slopes(x,y)

0 commit comments

Comments
 (0)