0

I have four dictionaries. And each value for each of the key in the dictionary is a 1D numpy array. I want to join all those numpy arrays into one. For example:

first dictionary =  {'feature1': array([0., 0., 1., 0.]),
'feature2': array([0., 1., 0., 0.]),
'feature3': array([1., 0., 0.,0.,0.,0.])}

 second dictionary = {'feature4': array([0.]),
'feature5': array([0., 0.]),
'feature6': array([0.023]),
'feature7': array([0.009]),
'feature8': array([0.])}

 third dictionary = {'feature9': array([  0.,   0.,   0., 912.,   0.,   0.,   0.]),
'feature10': array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]),}

The resultant final numpy should look like:

array([0., 0., 1., 0.,0., 1., 0., 0.,1., 0., 0.,0.,0.,0.,
      0.,0., 0.,0.023,0.009,0.,0.,
       0.,   0., 912.,   0.,   0.,   0.,0., 0., 0.,  0., 
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]

As an example I've made this dictionaries smaller but I have unto 50 keys in each of the dictionaries. So basically I want to join all of the numpy arrays in my dictionaries. How can I achieve this? Insights will be appreciated.

1 Answer 1

1

you could just do:

output = []

for dictionary in [firstdictionary,seconddictionary,thirddictionary]:
    for key, value in dictionary.items():
        output += list(value)
    
output_array = np.array(output)
Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I implemented a similar solution. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.