[英]convert dtype object with tuples into np.array
I have a dtype object e
: 我有一个dtype对象
e
:
>>> e
dtype([('cards', 'O'), ('store', 'O'), ('march', 'O'),
('fam', 'O'), ('cup', 'O'), ('sex', 'O'), ('educ', 'O'),
('age', 'O'), ('handedness', 'O')])
I want to make this into an array of strings: 我想把它变成一个字符串数组:
np.array(['cards','store','march','fam','cup','sex','educ','age','handedness'])
Is there a way to convert this object into an array as shown? 有没有办法将该对象转换为如图所示的数组?
I have tried the suggestions here: 我在这里尝试了建议:
How to convert a Numpy 2D array with object dtype to a regular 2D array of floats 如何将具有对象dtype的Numpy 2D数组转换为浮点数的常规2D数组
but I get the error: 但是我得到了错误:
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.
np.array(e.names)
dtype对象的names
属性是其字段名称的元组,如果没有字段,则为None
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.