Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import test as t
- import itertools
- from multiprocessing import Pool
- #Define the range of parameters 'alpha' and 'beta'.
- alpha, beta = np.arange(1,4), np.arange(1,4)
- def calc(x):
- i = alpha.tolist().index(x[0])
- j = beta.tolist().index(x[1])
- #The print statement tests what values of a, b it sees.
- print (t.a, t.b)
- #New values for a, b are set and used to calculate t.f(s).
- t.a, t.b = x[0], x[1]
- return (i, j, t.f(2))
- if __name__ == '__main__':
- #Storage array for the results.
- data = np.zeros((len(alpha), len(beta)))
- it = itertools.product(alpha, beta)
- pool = Pool(processes=2)
- results = pool.map(calc, it)
- #Constructing data from results.
- def constr(x):
- i, j, res = x
- #alpha index correspond to columns, beta index to rows.
- data[i, j] = res
- map(constr, results)
- pool.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement