目前我正在编写一个python脚本,它从文本文件中提取测量数据。我正在使用iPython笔记本和python2.7
现在我在使用numpy数组时遇到了一些奇怪的行为。我对此没有解释。在
myArray = numpy.zeros((4,3))
myArrayTransposed = myArray.transpose()
for i in range(0,4):
for j in range(0,3):
myArray[i][j] = i+j
print myArray
print myArrayTransposed
导致:
^{pr2}$因此,在不处理转置数组的情况下,将更新该数组中的值。在
这怎么可能?在
来自http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html:
执行transpose()时,将返回原始nArray的“视图”。它指向相同的内存缓冲区,但有不同的索引方案:
要创建独立的ndarray,可以使用数字阵列()操作员:
相关问题 更多 >
编程相关推荐