lundi 15 mars 2021

Python 3.8 multiprocessing for copying the random on MacOS

from multiprocessing import Pool, cpu_count
import numpy as np
from numpy.random import multivariate_normal

F = multivariate_normal(np.zeros(3), np.eye(3), (3, 5))

def test(k):
    print(k)
    res = np.zeros((5, 3))
    for i in range(3):
        res[:, i] = F[k, :, i]
        #print(res[:, i])
    return res


if __name__ == '__main__':
    with Pool(cpu_count()) as pool:
        result = pool.map(test, range(3))
    pool.close()
    pool.join()
    result = np.array(results)

In python3.6, the result is equal to the random matrix F. But their two matrices are different in python 3.8. This is just an example. In the real code, I want to pick up each column of F in each time step and do some operations on it.




Aucun commentaire:

Enregistrer un commentaire