简体   繁体   English

为什么这些在Python中定义多个数组的方法给出不同的答案?

[英]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.

相关问题 为什么两种numpy数组乘法方法给出不同的答案? - Why do two methods of numpy array multiplication give different answers? 为什么 matlab 和 python 对同一个数学问题给出不同的答案? - Why do matlab and python give different answers for the same mathematical question? 为什么这些基本转换器给出不同的答案? - Why do these base converters give different answers? 为什么在 python 中解决 Xc=y 的不同方法不应该给出不同的解决方案? - Why do different methods for solving Xc=y in python give different solution when they should not? pytz:为什么这些不同的方法会给出不同的UTC偏移量? - pytz: Why do these different methods give different UTC offsets? 对于二进制数组 sum(array) 和 numpy.count_nonzero(array) 当数组为 uint8 时,对于大数组给出不同的答案。 为什么? - For a binary array sum(array) and numpy.count_nonzero(array) give different answers for big arrays, when array is uint8. Why? 使用ScikitLearn进行多元线性回归,不同的方法给出不同的答案 - Multiple Linear Regression using ScikitLearn, different approaches give different answers python float vs numpy.float提供不同的答案吗? - python float vs numpy.float give different answers? 为什么我的机器人循环给了我多个答案? - Why does my bot loop give me multiple answers? 在Python中实现队列-两个isempty()方法给出不同的答案 - Implementing a queue in Python - two isempty() methods giving different answers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM