最近写代码在循环遍历一个数组时遇到报错:TypeError: 'numpy.int32' object is not iterable,将数组转化为list时仍报错:TypeError: 'int' object is not iterable。最后验证是因为数组、list的元素为int型造成,int型元素无法迭代。解决方法如下:
num= [0,1,2,3,4,5,6,7,8,9]
#方法一
num_new = [str(x) for x in num]
for i in range(len(num)):
print(num_new[i])
#方法二
num_new2 = list(map(lambda x:str(x), num))
for i in range(len(num)):
print(num_new2[i])



