I want to declare a numpy array (arr) with elements having a certain format, like this:
dt1 = np.dtype([('sec', '<i8'), ('nsec', '<i8')])
dt2 = np.dtype([('name', 'S10'), ('value', '<i4')])
arr = np.array([('x', dtype=dt1), ('y', dtype=dt2)])
The structure is something like this:
arr['x'] = elements with the format dt1 (sec and nsec)
arr['y'] = array of n elements with the format dt2 (name and value)
And the elements within should be accessed like this:
arr['x']['sec'], arr['x']['nsec'], arr['y'][0]['name'] etc.
But I get an invalid syntax error.
What is the correct syntax in this situation?
arr['x']= elements with the formatdt1(secandnsec)arr['y']= array ofnelements with the formatdt2(nameandvalue) And the elements within could be accessed like this:arr['x']['sec'],arr['x']['nsec'],arr['y'][0]['name']etc. Is it possible to represent it like this? Or is there a workaround this?