我正在做一个学期末的专题,我需要能够把一个矩阵的幂次,我需要使问题多线程。在
此代码在某些情况下有效,而在其他情况下则不行。我相信这与process_data函数中嵌套循环的逻辑有关,但我不确定我做错了什么!我已经为这个工作了几个星期了,我完全被难住了。这似乎与我的线程越界有关,但即使如此,我也不太确定,因为有些情况下线程超出了界限,但仍然正确地计算矩阵。在
请帮忙!在import copy
import numpy
import Queue
import random
import threading
import time
import timeit
# Create variable that determines the number of columns and
# rows in the matrix.
n = 4
# Create variable that determines the power we are taking the
# matrix to.
p = 2
# Create variable that determines the number of threads we are
# using.
t = 2
# Create an exit flag.
exitFlag = 0
# Create threading class.
class myThread (threading.Thread):
def __init__(self, threadID, name, q):
t

本文探讨了使用Python进行多线程矩阵乘法时遇到的问题,特别是当计算矩阵的高幂时。代码示例展示了如何创建线程进行矩阵运算,但存在在某些情况下的错误。作者指出,问题可能与process_data函数中的循环逻辑和线程边界有关,导致矩阵填充错误。寻求帮助以解决这个问题。
最低0.47元/天 解锁文章

2046

被折叠的 条评论
为什么被折叠?



