[英]Why do these methods of defining multiple arrays in Python give different answers?
I'm currently writing a programme in which two arrays are defined and then undergo singular value decomposition followed by some other processes to simulate some physics. 我目前正在编写一个程序,其中定义了两个数组,然后进行奇异值分解,然后再执行其他一些过程以模拟某些物理过程。 The arrays should be of dimension D² x D².
阵列的尺寸应为D²xD²。 I initially tried:
我最初尝试:
Ma, Mb = ( np.zeros([ pow(D, 2), pow(D,2)]) for i in range(2))
followed by 其次是
Ma = np . zeros ([ pow(D,2), pow(D,2)])
Mb = np . zeros ([ pow(D,2), pow(D,2)])
and finally 最后
Ma , Mb = [np . zeros ([ pow(D,2), pow(D,2)])]*2
I've found that defining the arrays in different ways affects my final answer, with only the final way giving me the answer I expect. 我发现以不同的方式定义数组会影响我的最终答案,只有最终的方式才能给出我期望的答案。 The first two options give me nonsensical answers.
前两个选项给了我毫无意义的答案。 Are these different methods actually equivalent or am I missing something?
这些不同的方法实际上等效吗?或者我缺少什么?
Edit: 编辑:
The code that follows is: 以下代码是:
for i in D_array:
for j in D_array:
for k in D_array:
for l in D_array:
Ma[k + D * j][i + D * l] = T[i][j][k][l]
Mb[k + D * l][i + D * j] = T[i][j][k][l]
where T and D_array were previously defined. 其中T和D_array是先前定义的。 After this Ma and Mb undergo SVD,
在Ma和Mb经历SVD之后,
The last way will have Ma is Mb
return true. 使
Ma is Mb
的最后一种方法Ma is Mb
返回true。 I find it surprising that that'd be the case you desire 我感到惊讶的是,您希望如此
Essentially the last one is equivalent to Mb = Ma = np . zeros ([ pow(D,2), pow(D,2)])
本质上,最后一个等于
Mb = Ma = np . zeros ([ pow(D,2), pow(D,2)])
Mb = Ma = np . zeros ([ pow(D,2), pow(D,2)])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.