How do you sort a numpy array by a nested dtype?
I want to sort a numpy array by the first element inside the array
import numpy as np
from random import randint
# create dummy data
test = np.array([[[randint(1, 10) for _ in range(3)]] for _ in range(10)])
dtype = [('response', [('x', 'f'),('y', 'f'),('x', 'f')])]
# convert over to dtype
test.astype(dtype)
How do I sort on a nested key? as the below doesn't work
np.sort(a, order='response.x')
What I would like to achieve is to use np.sort in the same way I would use sorted for a list
a_list = [[[randint(1, 10) for _ in range(3)]
sorted(a_list,key=lambda x: (x[0][0]))
But I would like to use np.sort as this is a sample of a much more complicated problem where I only have access to numpy arrays and would like to work with the numpy methods.
testsupposed to be(10, 1, 3)?z.