dtype is set to timedelta and then you want to pass string? Quite obviously numpy doesn't allow that, otherwise - what is the point of dtypes.
Maybe following can help:
Maybe following can help:
>>> person_data_def = [('name', 'm8'),('height', 'f8'),('weight', 'f8'),('age', 'i8')] >>> people_array = np.zeros(4, dtype=person_data_def) # you create 4-row array of zeros >>> people_array array([(0, 0., 0., 0), (0, 0., 0., 0), (0, 0., 0., 0), (0, 0., 0., 0)], dtype=[('name', '<m8'), ('height', '<f8'), ('weight', '<f8'), ('age', '<i8')]) >>> np.dtype(people_array[0][0]) # first element of first row dtype('<m8') >>> people_array[0][0] = 5 # accepts integer >>> people_array array([(5, 0., 0., 0), (0, 0., 0., 0), (0, 0., 0., 0), (0, 0., 0., 0)], dtype=[('name', '<m8'), ('height', '<f8'), ('weight', '<f8'), ('age', '<i8')]) >>> delta = np.array(50, dtype='<m8') >>> delta array(50, dtype=timedelta64) >>> people_array[1][0] = delta # accepts timedelta type >>> people_array array([( 5, 0., 0., 0), (50, 0., 0., 0), ( 0, 0., 0., 0), ( 0, 0., 0., 0)], dtype=[('name', '<m8'), ('height', '<f8'), ('weight', '<f8'), ('age', '<i8')]) >>> another_delta = np.array(60, dtype=np.timedelta64) >>> people_array[2] = (another_delta, 1, 2, 3) # accepts tuple of correct datatypes >>> people_array array([( 5, 0., 0., 0), (50, 0., 0., 0), (60, 1., 2., 3), ( 0, 0., 0., 0)], dtype=[('name', '<m8'), ('height', '<f8'), ('weight', '<f8'), ('age', '<i8')]) >>> people_array[0].dtype.names # get names ('name', 'height', 'weight', 'age') >>> people_array[0].dtype.fields mappingproxy({'name': (dtype('<m8'), 0), 'height': (dtype('float64'), 8), 'weight': (dtype('float64'), 16), 'age': (dtype('int64'), 24)}) >>> people_array['name'] array([ 5, 50, 60, 0], dtype=timedelta64) # name column values
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.