I have three dictionaries for example:
first_dictionary = {'Feature1': array([0, 0, 1, 0]),
'Feature2': array([0, 1, 0, 0]),
'Feature3': array([1, 0, 0])}
second_dictionary = { 'Feature4': array([0., 1.]),
'Feature5': array([0.]),
'Feature6': array([0., 1.])}
third_dictionary = {{'Feature7': array([ 0., 0., 0., 912., 0.,
0., 0., 0., 0., 0.]),
'Feature8': array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])}
Real dictionaries have a lot more keys (about 50 in each). I combine numpy array to produce a single 1D numpy array:
output = []
for dictionary in [first_dictionary,second_dictionary,third_dictionary]:
for key, value in dictionary.items():
output += list(value)
output_array = np.array(output)
However, when I do this the datatype are all messed where as I want to produce a final numpy array which maintains the datatype of original numpy arrays.
So what I get is:
array([ 0., 0., 1., 0., 0., 1., 0., 0., 1., 0., 0.,
0., 1., 0., 0., 1., 0., 0., 0., 912., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.])
Whereas, as you can you first dictionary only have integers so I want it to look like:
array([ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0,
0., 1., 0., 0., 1., 0., 0., 0., 912., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0.])
How can I achieve this? Insights will be appreciated. Side note: All of the numpy arrays in all of dictionaries were created using np.ndarray with type set to None.