Skip to content

Commit

Permalink
examples/wlsqm_example.py: Python 3 compatibility: use list comprehen…
Browse files Browse the repository at this point in the history
…sions instead of map() and filter()
  • Loading branch information
Technologicat committed Apr 25, 2017
1 parent c669865 commit fdc7e6c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/wlsqm_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def testmany2d():
nk = np.empty( (npoints,), dtype=np.int32 ) # number of neighbors, i.e. nk[i] is the number of actually used columns in hoods[i,:]
for i in range(npoints):
I = tree.query_ball_point( S[i], r ) # indices of neighbors of S[i] at distance <= r (but also including S[i] itself!)
I = filter( lambda idx: idx != i, I ) # exclude S[i] itself
I = [ idx for idx in I if idx != i ] # exclude S[i] itself
if len(I) > max_nk:
I = I[:max_nk]
I = np.array( I, dtype=np.int32 )
Expand Down Expand Up @@ -463,7 +463,7 @@ def test3d():
if points_per_axis % 2 == 1:
point_list = S.tolist()
oldlen = len(point_list)
point_list = filter( lambda item: not (abs(item[0]) < 1e-8 and abs(item[1]) < 1e-8 and abs(item[2]) < 1e-8), point_list )
point_list = [item for item in point_list if not (abs(item[0]) < 1e-8 and abs(item[1]) < 1e-8 and abs(item[2]) < 1e-8)]
S = np.array(point_list)
if len(point_list) < oldlen:
print( "Sudoku LHS sampled the point at the origin; discarding it from the sample" )
Expand Down Expand Up @@ -530,7 +530,7 @@ def test3d():

# check exact solution and relative error
#
exact = np.array( map( lambda func : func( xi[0], xi[1], xi[2] ), funcs ) )
exact = np.array( [func( xi[0], xi[1], xi[2] ) for func in funcs] )
err = (fi - exact)

print()
Expand Down Expand Up @@ -743,7 +743,7 @@ def test2d():
if points_per_axis % 2 == 1:
point_list = S.tolist()
oldlen = len(point_list)
point_list = filter( lambda item: not (abs(item[0]) < 1e-8 and abs(item[1]) < 1e-8), point_list )
point_list = [ item for item in point_list if not (abs(item[0]) < 1e-8 and abs(item[1]) < 1e-8) ]
S = np.array(point_list)
if len(point_list) < oldlen:
print( "Sudoku LHS sampled the point at the origin; discarding it from the sample" )
Expand Down Expand Up @@ -807,7 +807,7 @@ def test2d():

# check exact solution and relative error
#
exact = np.array( map( lambda func : func( xi[0], xi[1] ), funcs ) )
exact = np.array( [func( xi[0], xi[1] ) for func in funcs] )
err = (fi - exact)

print()
Expand Down Expand Up @@ -1153,7 +1153,7 @@ def test1d():

# check exact solution and relative error
#
exact = np.array( map( lambda func : func( xi ), funcs ) )
exact = np.array( [func( xi ) for func in funcs] )
err = (fi - exact)

print()
Expand Down

0 comments on commit fdc7e6c

Please sign in to comment.