Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Numpy数组更改值_Python_Numpy - Fatal编程技术网

Python Numpy数组更改值

Python Numpy数组更改值,python,numpy,Python,Numpy,我有以下代码,我不明白为什么数组只在第一次更改: 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

我有以下代码,我不明白为什么数组只在第一次更改:

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çois Fabre在评论中解决。显然,在Python3中,输入返回一个字符串。

Python2或3?因为在Python3
input
中返回一个string.python3,所以这就是问题所在:D。。。谢谢python 2还是3?因为在Python3
input
中返回一个string.python3,所以这就是问题所在:D。。。谢谢