#39;numpy.float64#39; object is not iterable(numpy.float64 对象不可迭代)
问题描述
我正在尝试迭代使用 numpy.linspace 生成的值数组:
I'm trying to iterate an array of values generated with numpy.linspace:
slX = numpy.linspace(obsvX, flightX, numSPts)
slY = np.linspace(obsvY, flightY, numSPts)
for index,point in slX:
yPoint = slY[index]
arcpy.AddMessage(yPoint)
这段代码在我的办公室电脑上运行良好,但我今天早上坐在家里的另一台机器上工作,出现了这个错误:
This code worked fine on my office computer, but I sat down this morning to work from home on a different machine and this error came up:
File "C: empgssm_arcpy.1.0.3.py", line 147, in AnalyzeSightLine
for index,point in slX:
TypeError: 'numpy.float64' object is not iterable
slX 只是一个浮点数组,脚本打印内容没有问题——只是,显然是迭代它们.关于导致它崩溃的任何建议以及可能的修复方法?
slX is just an array of floats, and the script has no problem printing the contents -- just, apparently iterating through them. Any suggestions for what is causing it to break, and possible fixes?
推荐答案
numpy.linspace() 为您提供一维 NumPy 数组.例如:
numpy.linspace() gives you a one-dimensional NumPy array. For example:
>>> my_array = numpy.linspace(1, 10, 10)
>>> my_array
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
因此:
for index,point in my_array
无法工作.您将需要某种二维数组,其中包含两个二维元素:
cannot work. You would need some kind of two-dimensional array with two elements in the second dimension:
>>> two_d = numpy.array([[1, 2], [4, 5]])
>>> two_d
array([[1, 2], [4, 5]])
现在你可以这样做了:
>>> for x, y in two_d:
print(x, y)
1 2
4 5
这篇关于'numpy.float64' 对象不可迭代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:'numpy.float64' 对象不可迭代
基础教程推荐
- 包装空间模型 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- 求两个直方图的卷积 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
