[Numpy-discussion] tiny bug in MLab.py
Charles G Waldman
cgw at alum.mit.edu
Fri May 10 14:39:02 EDT 2002
>>> import Numeric
>>> import MLab
>>>
>>> a=Numeric.ones(4)
>>> b=Numeric.ones(4)
>>>
>>> print MLab.corrcoef(a,b)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "MLab.py", line 230, in corrcoef
c = cov(x, y)
File "MLab.py", line 237, in cov
if y != None: m = concatenate((m,y))
TypeError: function not supported for these types, and can't coerce to
supported types
This is happening because of some comparisons of array objects to
None. You can't say "a != None" for array objects. (Maybe you should
be able to?)
Anyhow, the following patch corrects the misbehavior:
--- MLab.py.orig Fri May 10 16:12:52 2002
+++ MLab.py Fri May 10 16:36:42 2002
@@ -34,7 +34,7 @@
"""eye(N, M=N, k=0, typecode=None) returns a N-by-M matrix where the
k-th diagonal is all ones, and everything else is zeros.
"""
- if M == None: M = N
+ if M is None: M = N
if type(M) == type('d'):
typecode = M
M = N
@@ -46,7 +46,7 @@
"""tri(N, M=N, k=0, typecode=None) returns a N-by-M matrix where all
the diagonals starting from lower left corner up to the k-th are all ones.
"""
- if M == None: M = N
+ if M is None: M = N
if type(M) == type('d'):
typecode = M
M = N
@@ -197,7 +197,7 @@
"""trapz(y,x=None,axis=-1) integrates y along the given dimension of
the data array using the trapezoidal rule.
"""
- if x == None:
+ if x is None:
d = 1.0
else:
d = diff(x,axis=axis)
@@ -234,7 +234,7 @@
def cov(m,y=None):
m = asarray(m)
mu = mean(m)
- if y != None: m = concatenate((m,y))
+ if y is not None: m = concatenate((m,y))
sum_cov = 0.0
for v in m:
sum_cov = sum_cov+multiply.outer(v,v)
More information about the NumPy-Discussion
mailing list