为什么这样可以修改数组a
import numpy as np a = np.arange(0,60,5) a = a.reshape(3,4) print ("原数组是:",a) for x in np.nditer(a, op_flags=['readwrite']): x[...]=2*x print ('修改后的数组是:',a)
对 a 进行遍历每个元素的值翻倍
nditer是一个迭代器,可以遍历数组中的每个元素,for循环的意思是将每个元素都乘2了