Concetenating arrays in a dictionary
Say I have a Python dictionary with 100's of keys. For each key, the
dictionary holds a 2D array.
All these 2D arrays have the same number of rows. How can I concatenate
these arrays efficiently in a final 2D array along the column axis?
Is it worth going through Pandas for this? If so, how?
E.g.
from collections import OrderedDict()
dct = OrderedDict()
for key in xrange(3):
dct[key] = np.random.randint(3,size=(2,np.random.randint(10)))
# Print the dictionary:
> dict(dct)
{0: array([[1, 0, 2, 2, 2, 1, 0],
[1, 2, 2, 1, 1, 1, 0]]),
1: array([[2, 1, 0, 1, 1],
[1, 1, 2, 2, 2]]),
2: array([[2],
[0]])}
The result of the concatenation should be:
array([[1, 0, 2, 2, 2, 1, 0, 2, 1, 0, 1, 1, 2],
[1, 2, 2, 1, 1, 1, 0, 1, 1, 2, 2, 2, 0]])
No comments:
Post a Comment