Python - Multi processing to mount an array

后端 未结 3 1787
故里飘歌
故里飘歌 2021-01-26 10:58

I m using griddata to \"mount\" array with a great number of shapes and i would like to know if i can calculate functions (on each slice) on each my 4 cores in order to accelera

3条回答
  •  梦谈多话
    2021-01-26 11:30

    Three things:

    1. The most important question is why are you doing this?.
    2. Your NumPy build may already be making use of multiple cores. I am not sure off the top of my head how to check, see questions like this or if absolutely necessary take a look at the Numexpr library https://github.com/pydata/numexpr
    3. About the "Y" in your likely XY problem - you are re-calculating data that you can instead re-use:

    .

    import numpy
    
    size = 8
    Y=(arange(2000))
    X=(arange(2000))
    (xx,yy)=meshgrid(X,Y)
    
    array = zeros((Y.shape[0], X.shape[0], size))
    
    array[..., 0] = 0    
    for i in range(1, size):
        array[..., 1] = X ** i + Y ** i + array[..., i - 1]
    

提交回复
热议问题