我有以下代码,我不明白为什么数组只在第一次更改:
a = numpy.zeros(10)
old = 0
for i in range(100):
if i % 10 == 5:
new = input('New value of array entries?')
for xi in range(10):
if a[xi] == old:
a[xi] = new
old = new
print(a)
输出:
New value of array entries?2
[ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
New value of array entries?1
[ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
New value of array entries?3
[ 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.]
编辑:@ Jean-FrançoisFabre在评论中解决了这个问题。显然在Python 3中输入一个字符串。