From a8d66ebeea852f5170075ffda064af9ff898ae03 Mon Sep 17 00:00:00 2001 From: Per A Brodtkorb Date: Mon, 30 May 2016 16:58:21 +0200 Subject: [PATCH] Added test to lazywhere + pep8 on polynomial --- wafo/misc.py | 4 ++++ wafo/polynomial.py | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/wafo/misc.py b/wafo/misc.py index e022728..505643f 100644 --- a/wafo/misc.py +++ b/wafo/misc.py @@ -189,8 +189,12 @@ def lazywhere(cond, arrays, f, fillvalue=None, f2=None): >>> a, b = np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]) >>> def f(a, b): ... return a*b + >>> def f2(a, b): + ... return np.ones(np.shape(a))*np.ones(np.shape(b)) >>> lazywhere(a > 2, (a, b), f, np.nan) array([ nan, nan, 21., 32.]) + >>> lazywhere(a > 2, (a, b), f, f2=f2) + array([ 1., 1., 21., 32.]) Notice it assumes that all `arrays` are of the same shape, or can be broadcasted together. diff --git a/wafo/polynomial.py b/wafo/polynomial.py index aa67d7a..f171981 100644 --- a/wafo/polynomial.py +++ b/wafo/polynomial.py @@ -650,9 +650,8 @@ def poly2hstr(p, variable='x'): # We need the coefficient only if it is different from 1 or -1 or # when it is the constant term. - needcoef = ( - (abs(coef) != 1) | ( - expon == 0) & isfirst) | 1 - isfirst + needcoef = ((abs(coef) != 1) | + (expon == 0) & isfirst) | 1 - isfirst # We need the variable except in the constant term. needvar = (expon != 0)