i have structured numpy
array, in 1 of field has subfields:
import numpy, string, random dtype = [('name', 'a10'), ('id', 'i4'), ('size', [('length', 'f8'), ('width', 'f8')])] = numpy.zeros(10, dtype = dtype) idx in range(len(a)): a[idx] = (''.join(random.sample(string.ascii_lowercase, 10)), idx, numpy.random.uniform(0, 1, size=[1, 2]))
i can sorted of fields, this:
a.sort(order = ['name']) a.sort(order = ['size'])
when try sort structured field ('size' in example), getting sorted first subfield ('length' in example). however, have elements sorted 'height'. tried this, not work:
a.sort(order = ['size[\'height\']'])) valueerror: unknown field name: size['height'] a.sort(order = ['size', 'height']) valueerror: unknown field name: height
therefore, wonder, if there way accomplish task?
i believe want:
a[a["size"]["width"].argsort()]
Comments
Post a Comment