0

I have a dtype object 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

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.

1 Answer 1

0
np.array(e.names)

The names attribute of a dtype object is a tuple of its field names, or None if it doesn't have fields.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.