打印NDimensional Numpy矩阵时出错

2024-07-08 13:41:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我有问题与打印一个numpy 6维矩阵。 将numpy作为np导入 Q矩阵=np.零(((5,6,10,12,10,8)【】

我用了这个,填充完矩阵后,我试着用

print (QMatrix)

然后它变成一堆零。但是当我在矩阵中搜索一个值时,它会给出正确的值。你知道吗

print (QMatrix[1][2][4][2][5][7])
>>> 12.45

在打印矩阵之前,我需要转换矩阵吗 这是我使用的完整代码

class Q_Matrix_Base(object):
 def __init__(self, LeadVehSpd,LeadVehiPos,EstDiscTime,FolVehSpeed,FolVehPos,RGT):
        self.LeadVehSpd = LeadVehSpd
        self.LeadVehiPos = LeadVehiPos
        self.EstDiscTime = EstDiscTime
        self.FolVehPos = FolVehPos
        self.FolVehSpeed = FolVehSpeed
        self.RGT = RGT

        # initialize matrix and fill with zeroes
        self.QMatrix =  np.zeros((((((LeadVehSpd,LeadVehiPos,EstDiscTime,FolVehSpeed,FolVehPos,RGT))))))
        #self.QMatrix.fill(0)

 def setitem (self ,LeadVehSpd,LeadVehiPos,EstDiscTime,FolVehSpeed,FolVehPos,RGT,Reward): #assign the values for the specific place


      self.QMatrix[LeadVehSpd,LeadVehiPos,EstDiscTime,FolVehSpeed,FolVehPos,RGT] = Reward

 def getitem (self,LeadVehSpd,LeadVehiPos,EstDiscTime,FolVehSpeed,FolVehPos,RGT): #get the value from a row and a column
    return self.QMatrix[LeadVehSpd][LeadVehiPos][EstDiscTime][FolVehSpeed][FolVehPos][RGT]

 def printMaa (self,lk):
    np.save('C:\\example\\MatrixsecondStage2.npy', self.QMatrix)
    return self.QMatrix

 def getposspeed (self,LeadVehSpd,LeadVehiPos,EstDiscTime,FolVehPos,RGT): #to select a specific row(i) in a matrix
    return self.QMatrix[LeadVehSpd,LeadVehiPos,EstDiscTime,:,FolVehPos,RGT]

Tags: theselfnumpyreturndefnp矩阵print

热门问题