Python [0,0]表达式的作用是什么?

Python [0,0]表达式的作用是什么?,python,numpy,Python,Numpy,我有一句话: theta1 = zeros((3,2)) #this is a 3x2 matrix theta0 = zeros((2,1)) #this is a 2x1 matrix thetares = theta1.dot(theta0) #3x2 * 2x1 -> 3x1 res0 = thetares.T.dot(thetares)[0,0] #result 0.0 res1 = thetares.T.dot(thetares) #result [[0.]] 但

我有一句话:

theta1 = zeros((3,2)) #this is a 3x2 matrix
theta0 = zeros((2,1)) #this is a 2x1 matrix
thetares = theta1.dot(theta0) #3x2 * 2x1 -> 3x1

res0 = thetares.T.dot(thetares)[0,0] #result 0.0
res1 = thetares.T.dot(thetares)      #result [[0.]]

但是我不知道,res0表达式末尾的[0,0]是什么意思。res0和res1的结果将是一个1x1矩阵

色域和色域转置的点积可能会产生一个二维numpy数组。所以从点积的结果中取第一个值,在索引[0,0]处。
理解这一点的最佳方法是从res0中删除[0,0]部分并比较结果。

res1是点积运算后的矩阵(1x1矩阵)。根据代码,res0是res1的位置(0,0)处的元素。

[0,0]表示您查看第0行第0列的元素。它获取位置(0,0)处的元素,从而将唯一的元素作为标量返回。正如您在输出中看到的一样。您可能需要仔细阅读Python列表和NumPy数组索引。res0不完全是1x1矩阵。它是点运算后的结果矩阵的第一个元素res1应该非常清楚,一旦你意识到
.T
做的正是你认为它做的,并且记住A.T*A=I\n。对于矩阵A和n维恒等式。