Parallel mapping functions in IPython w/ multiple parameters

后端 未结 5 897
闹比i
闹比i 2021-01-30 21:05

I\'m trying to use IPython\'s parallel environment and so far, it\'s looking great but I\'m running into a problem. Lets say that I have a function, defined in a library

<
5条回答
  •  孤街浪徒
    2021-01-30 22:01

    let's build on that:

    dview.map_sync(func, [myA]*len(myLongList), myLongList)
    

    maybe the following would work:

    from itertools import izip_longest
    dview.map_sync(func, izip_longest(myLongList, [], fillvalue=myA))
    

    example:

    >>> # notice that a is a tuple
    ... concat = lambda a: '%s %s' % a
    >>> mylonglist = range(10)
    >>> from itertools import izip_longest
    >>> map(concat, izip_longest(mylonglist, [], fillvalue='mississippi'))
    ['0 mississippi', '1 mississippi', '2 mississippi', '3 mississippi',
    '4 mississippi', '5 mississippi', '6 mississippi', '7 mississippi',
    '8 mississippi', '9 mississippi']
    

提交回复
热议问题