Given a list of points I would like to create a numpy array with coordinates. Related questions are here and here. Does anyone know the correct or a more efficient way of doing this?
import numpy as np
# Please note that we have no control over the point class.
# This code just to generate the example.
class Point:
x = 0.0
y = 0.0
points = list()
for i in range(10):
p = Point()
p.x = 10.0
p.y = 5.0
points.append(p)
# The question starts here.
# The best I could come up with so far:
x = np.fromiter((p.x for p in points), float)
y = np.fromiter((p.y for p in points), float)
arr = np.vstack((x,y)).transpose()