0

i have a dictionary array like so :

myary= {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9} i would like to convert it to a 2d array somthing like this in:: numpy.matrix(myary) out:: 1 2 3 4 5 6 7 8 9 is this even possible to do to convert a dictionary with keys and value to a 2D array with only values

o3203823
  • 63
  • 1
  • 11
  • i dont even see how this is related – o3203823 Dec 26 '18 at 05:58
  • Um...use `values()` on your dictionary to get a flat list of values, and then apply the accepted numpy answer from the dupe link. What isn't clear? – Tim Biegeleisen Dec 26 '18 at 05:59
  • Do the keys play any role here? It looks like you can just dump the values into the array. – Mark Dec 26 '18 at 06:03
  • this is just a small part of a bigger problem but to begin with i need to first convert that array in to a 2D array consisting of only values – o3203823 Dec 26 '18 at 06:19

1 Answers1

1
myary= {'1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9}
l=[x for x in myary.values()]
l.sort()
step=3
print([x for x in [l[start:start+step] for start in range(0,len(l),step)]])
#[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Bitto
  • 7,937
  • 1
  • 16
  • 38