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.
Community
  • 1
  • 1

1 Answers1

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.

user2357112
  • 260,549
  • 28
  • 431
  • 505