I have a situation in which I would like to do the following:
import numpy as np
type1 = np.dtype([('col1', 'i'), ('col2', 'i')])
type2 = np.dtype([('cols', type1), ('info', 'S32')])
data = np.zeros(10, type2)
# The following doesn't work, but I want to do something similar
index = ['cols']['col1']
# Set column ['cols']['col1'] to 5
data[index] = 5
# I can only get this to work if I do the following:
index = "['cols']['col1']"
eval('data' + index '= 5') # kinda scary
This doesn't work, but I found a workaround using the exec function but that feels pretty hacky. Does anyone have any suggestions how to programmatically create an index for nested structured numpy datatypes?
Thanks
data['cols']['col1'] =5?index1, index2 = 'cols', 'col1'and useddata[index1][index2]?