Вот решение с использованием Pool и Pool.map.
from multiprocessing import Pool, cpu_count
import numpy as np
def unit_vector(vector):
return vector / np.linalg.norm(vector)
def angle_between(v1, v2):
#if you want to maximize speed, avoid making variables
#v1_u = unit_vector(v1)
#v2_u = unit_vector(v2)
return np.arccos(np.clip(np.dot(unit_vector(v1_u),unit_vector(v2_u)),-1.0,1.0))
def calc_angle(_list):
#use list unpacking instead of instantiate variables
return angle_between(*_list)
a=[[1,1,1],[1,2,1],[6,4,5]]
b=[[1,0,0],[6,2,2],[1,9,2]]
with Pool(cpu_count()) as p: #use the context manager
angles = p.map(calc_angle, zip(a,b))
Выход:
>>> angles
[0.9553166181245092, 0.7398807743787404, 0.8775836986593762]