Working with a map in python

I am trying to figure out how to use the map correctly in python so that I can multi-thread my Pool.map program. I mostly run into problems trying to understand how functional python works. I have:

import numpy as np

def maptest(foo,bars):
   print foo * bars

main():
   matA = np.eye(2)
   matB = np.eye(2)

   print map((lambda foo: maptest(foo, matB)), matA) 

This gives me the conclusion:

[[ 1.  0.]
 [ 0.  0.]]
[[ 0.  0.]
 [ 0.  1.]]
[None, None]

when the output i want is simple:

[[1. 0.]
 [0. 1.]]

What happens with a card call? This is my first time using a map and lambda. I used lambdify with sympy, but that's all for my functionalities. Thank!

+3
source share
1 answer

[No, No] comes from printing a map call (note that your maptest function prints!).

, , , . mapA , . , [1,0] [[1,0] [0,1]], [0,1] [[1,0] [0,1]]. , mapA.

+5

All Articles