1

I have a numpy.dtype that resembles the following:

dtype([('value1','<f8'),('value2','<f8')...])

I'd like to get the first part of each tuple (i.e. the value part) into a list, and the second part of each tuple into a separate list. The dtype object does not appear to be an iterable. How do I go about generating these lists? Thank you.

4

1 回答 1

1

您可以迭代dtype.descr

>>> d = np.dtype([('value1','<f8'),('value2','<f8')])
>>> [x[0] for x in d.descr]
['value1', 'value2']

和:

>>> [x[1] for x in d.descr]
['<f8', '<f8']
于 2013-07-26T13:19:06.527 回答