【发布时间】:2013-04-25 17:47:49
【问题描述】:
我想从 python 中的数组中减去一个数字,但我想保留原始数组。
这是我的代码:
for X0 in [X0 * 0.01 for X0 in range(-2,2)]:
for Y0 in [Y0 * 0.01 for Y0 in range(6,10)]:
RAm = RA
Decm = Dec
RAm[:] = [x - X0 for x in RAm]
Decm[:] = [x - Y0 for x in Decm]
RAs = np.sum(RAm)
Decs = np.sum(Decm)
#a = np.sqrt(((RAs**2*Decs**2)**2 - RAs**4*Decs**4)/(RAs**2*Decs**2*Decs**2 -Decs**2*RAs**4))
#b = np.sqrt(((RAs**2*Decs**2)**2 - RAs**4*Decs**4)/(RAs**2*Decs**2*RAs**2 - RAs**2*Decs**4))
print RA
print RAm
这让我知道 RA 正在发生变化,即使它应该保持不变,因为我想在每个循环中从 RA 中减去一个不同的数字。我该如何解决这个问题?
【问题讨论】:
-
您是否将
numpy.arrays 与常规lists 混合使用?如果是,为什么?
标签: python arrays loops for-loop