我在Python非常初學者。 我有矩陣乘法的問題。 我使用列表(矩陣)列表從txt文件中讀取矩陣。矩陣乘法在Python,多處理
當我想用多我有鴻溝列出了問題和池功能使用新的列表。
我該如何解決這個問題?
請從評論幫助
def matrix_multiplication(list1, list2):
A = numpy.matrix(list1)
B = numpy.matrix(list2)
return A*B
def counting(dane):
left_matrix = matrices[0]
for matrix in matrices[1:]:
left_matrix = numpy.matrix(left_matrix)
matrix = numpy.matrix(matrix)
left_matrix = matrix_multiplication(left_matrix, matrix)
if __name__ == "__main__":
matrices = []
with open('sample-probka2.txt', 'r') as file:
matrix_reader = csv.reader(file, delimiter=';')
current_matrix = []
for row in matrix_reader:
if len(row) == 0:
matrices.append(current_matrix)
current_matrix = []
else:
current_matrix.append(list(map(float, row)))
print (matrices)
counting(matrices)
np = multiprocessing.cpu_count()
print('You have', np, 'processors')
matrices2 = numpy.array_split(matrices, np)
print(matrices2)
pool = Pool(processes=np)
count = pool.starmap(liczenie, matrices2)
print count
錯誤,與企圖恢復格式化:
multiprocessing.pool.RemoteTraceback:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py",
line 119, in worker result = (True, func(*args, **kwds))
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 47,
in starmapstar return list(itertools.starmap(args[0], args[1])) TypeError: counting() takes 1 positional argument but 61 were given
你得到的錯誤是什麼? – Aaron
multiprocessing.pool.RemoteTraceback: 「」「 Traceback(最近呼叫的最後一個): File」/Library/Frameworks/Python.framework/Versions/3。6/lib/python3.6/multiprocessing/pool.py「,第119行,在worker result =(True,func(* args,** kwds)) File」/Library/Frameworks/Python.framework/Versions/ 3.6/lib/python3.6/multiprocessing/pool.py「,第47行,在starmapstar 返回列表(itertools.starmap(args [0],args [1])) TypeError:counting()取1個位置參數,但61給予 「」「 –
在我看來,我應該修改'矩陣2'。在這種情況下,我不能使用'pool.starmap(計數,矩陣2)。我應該改變一些東西,但我不知道是什麼。 –