Object 'numpy.float64' does not repeat

I am trying to iterate through an array of values ​​created using 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 another machine, and this error occurred:

 File "C:\temp\gssm_arcpy.1.0.3.py", line 147, in AnalyzeSightLine for index,point in slX: TypeError: 'numpy.float64' object is not iterable 

slX is just an array of floats, and the script has no problem printing content - it just seems to iterate through them. Any suggestions on what causes his violation, and possible corrections?

+6
source share
1 answer

numpy.linspace() gives you a one-dimensional NumPy array. For instance:

 >>> my_array = numpy.linspace(1, 10, 10) >>> my_array array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]) 

In this way:

 for index,point in my_array 

can't work. You will 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]]) 

Now you can do this:

 >>> for x, y in two_d: print(x, y) 1 2 4 5 
+6
source

Source: https://habr.com/ru/post/946265/


All Articles