Given a list of dictionaries as follows:
dict_data = [
{'name': 'r1', 'interval': [1800.0, 1900.0], 'bool_condition': [True, False]},
{'name': 'r2', 'interval': [1600.0, 1500.0], 'bool_condition': [False]},
{'name': 'r3', 'interval': [1400.0, 1600.0], 'bool_condition': [True]}
]
I would like to create a record array from the dictionaries data.
But when I try the following I get ValueError
import numpy as np
dt = np.dtype([
('name', np.str_, 50), ('interval', np.float64, (2,)),
('bool_condition', np.bool)
])
values = [tuple(val.values()) for val in dict_data]
arr = np.rec.array(values, dtype=dt)
Error:
ValueError: cannot set an array element with a sequence
I would like to know how could I have a more correct dtype
and then create the record array from the list of dictionaries.