There might be smarter ways on doing this but the following gives you the correct output I think; you can use structured arrays:
import numpy as np
dat = [['User1', 'Male', '2.2'], ['User2', 'Female', '3.777'], ['User3', 'Unknown', '0.0']]
# create data types: two strings of length 10 and float
dt = np.dtype('a10, a10, float')
# convert the inner lists to tuples so that a structured array can be used
for ind, l in enumerate(dat):
dat[ind] = tuple(l)
# convert dat to an array
my_arr = np.array(dat, dt)
Output:
array([('User1', 'Male', 2.2), ('User2', 'Female', 3.777),
('User3', 'Unknown', 0.0)],
dtype=[('f0', 'S10'), ('f1', 'S10'), ('f2', '<f8')])
You can also give names to the columns by doing:
dt = {'names': ['user', 'gender', 'number'], 'formats':['a10', 'a10', 'float']}
my_arr = np.array(dat, dt) # dat is the list with tuples, see above
The output now is:
array([('User1', 'Male', 2.2), ('User2', 'Female', 3.777),
('User3', 'Unknown', 0.0)],
dtype=[('user', 'S10'), ('gender', 'S10'), ('number', '<f8')])
And you can then access a single column by doing e.g.
my_arr['number']
array([ 2.2 , 3.777, 0. ])
my_arr['user']
array(['User1', 'User2', 'User3'], dtype='|S10')
I would recommend to use a dataframe from Python pandas where you can easily deal with different data types and complex data structures.
For your example:
import pandas as pd
pd.DataFrame(dat, columns=['user', 'gender', 'some number'])
would then simply give you:
user gender some number
0 User1 Male 2.2
1 User2 Female 3.777
2 User3 Unknown 0.0