I have dictionary like this:
a = dict(zip( ['k1', 'k2', 'k3', 'k4'],
... [ [1,2,3,4], [10,20,30,40], [100,200,300,400], [1000,2000,3000,4000]])
>>> a
{'k1': [1, 2, 3, 4], 'k2': [10, 20, 30, 40], 'k3': [100, 200, 300, 400], 'k4': [1000, 2000, 3000, 4000]}
What I want to do: get values for several keys and create multidimensional numpy array from them. Something like this:
result = numpy.array( [a[x] for x in ('k1' , 'k3')]
I tried this code:
ar = numpy.array([])
for el in ['k1', 'k3']:
ar = numpy.r_[ar, num_dict[el]]
ar = ar.reshape(2,len(ar)/2)
But are there some built in functions or more elegant ways?