I have a dtype as follows:
pose_dtype = np.dtype([('x', np.float64), ('y', np.float64), ('theta', np.float64)])
Right now, I can write:
pose = np.array((1, 2, np.pi), dtype=pose_dtype)
I'd like to add an xy
field to make this easier to work with. I can do this with:
pose_dtype = np.dtype(dict(
names=['x', 'y', 'theta', 'xy'],
formats=[np.float64, np.float64, np.float64, (np.float64, 2)],
offsets=[0, 8, 16, 0]
))
However, now I can no longer construct the array using my previous method, and have to resort to:
pose = np.array((1, 2, np.pi, [1, 2]), dtype=pose_dtype)
Which is dangerously repetitious.
Is there any way I can mark the properties as aliases of one another, so that I don't have to deal with this?
Experiments in filling an array by field rather than by record
another way of getting the 2 fields as a float array (not pretty)