我是python的新手。我目前正在尝试应用多处理模块以从矩阵计算svd。有人可以指导我解决该问题的正确代码吗?
我已经尝试了多处理池来解决问题,但是给了我
"TypeError: 'tuple' object is not callable".
我希望得到它的处理时间,以便我可以比较在进行多处理之前和之后进行svd计算所需的时间
import time
from multiprocessing import Pool
import numpy as np
def svd_matrix(numbers):
A = np.array([[1.176, 0.789, 1.3776, 1.0093],
[0.9242, 0.4534, 0.5212, 0.7524],
[0.2518, 0.3556, 0.8564, 0.2568],
[0.9242, 0.4534, 0.5212, 0.7524]])
for number in numbers:
start_time = time.time()
p = Pool()
result = p.map(svd(A),numbers)
p.close()
p.join()
end_time = time.time() - start_time
print(f"SVD calculation took {end_time} s using multiprocessing pool")
if __name__ == '__main__':
numbers = A
svd_matrix(numbers)