Reputation: 1167
I have a 1-D array in numpy whose shape is (761,) and each entry is a 10 tuple whose elements I can't access independently. The dtype is
array1.dtype
dtype([('Name', '|S58'), ('Category', '|S32'), ('HQLocation', '|S34'),
('YearFounded', '<i8'), ('Latitude', '<f8'), ('Longitude', '<f8'),
('TotalFundingAmount', '<i8'), ('LastFundingAmount', '<i8'),
('Investors', '<i8'), ('NGrams', '|S98')])
An example row is array1[578]
('"FoxyP2, Inc."', 'Education', '"Cuajimalpa, Mexico"', 2006, 19.3547,
-99.3001, 55317213, 42999977, 3,
'english;learning;reinvent;experience;english learning')
I'm trying to make this into a 2-D array whose shape is (761,10) while keeping the column names and data types.
Upvotes: 1
Views: 205
Reputation: 20339
It's just impossible with your input, as the different columns don't have the same type: some of them are strings, some are floats, some integers.
NumPy arrays are homogeneous, meaning that all entries must have the same data type. This data type can be simple (int
, float
, ...) or complicated (like a tuple whose first element is a "|S58"
, whose fourth is a int
, whose fifth is a float
...), but in any case, all the entries have the same type. You can get more information in the documentation, here and here.
But why do you need a 2D array? You can access and manipulate each column independently with indexing (eg, your_array[YearFounded]
will return your fourth column)...
Upvotes: 2