【发布时间】:2023-03-16 19:41:01
【问题描述】:
我有一个 dtype 对象e:
>>> e
dtype([('cards', 'O'), ('store', 'O'), ('march', 'O'),
('fam', 'O'), ('cup', 'O'), ('sex', 'O'), ('educ', 'O'),
('age', 'O'), ('handedness', 'O')])
我想把它变成一个字符串数组:
np.array(['cards','store','march','fam','cup','sex','educ','age','handedness'])
有没有办法将此对象转换为数组,如图所示?
我已经尝试过这里的建议:
How to convert a Numpy 2D array with object dtype to a regular 2D array of floats
但我得到了错误:
ValueError Traceback (most recent call last)
<ipython-input-160-dc37d6f17f2f> in <module>()
----> 1 np.array(list(e[:, 1]), dtype=str)
ValueError: Field key must be an integer, string, or unicode.
【问题讨论】:
标签: python