How to parse a numpy array?

I have a Numpy array:

[[12 13 14],[15 16 17],[18 19 20]]

How do i get this

[[12, 13, 14], [15, 16, 17],[18 ,19, 20]]
+5
source share
1 answer

When you see a numpy array printed without commas, you just look at its string representation. If you want it to be printed with commas, you can convert it to a Python list:

In [45]: print(arr)
[[12 13 14]
 [15 16 17]
 [18 19 20]]

In [46]: arr_list = arr.tolist()

In [47]: print(arr_list)
[[12, 13, 14], [15, 16, 17], [18, 19, 20]]
+13
source

All Articles