I want to write a code that return counts is [1,2,3,4] while keeping the parallelized for loop. I'm trying to update the global array counts from the inside of increment function, but it never works and returns [0,0,0,0]. Is there any way than I can update the counts array from the increment function while parallel looping increment function?
import numpy as np
import multiprocessing as mpp
import timeit
start = timeit.default_timer()
num=5
counts=np.zeros((num,1))
def increment(k):
    global counts
    counts[k]=counts[k]+k
pool = mpp.Pool(4)
pool.map(increment,[k for k in range(0,num)])
print(counts)
stop = timeit.default_timer()
print('Time: ', stop - start)