Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse a numpy array?

Tags:

python

numpy

I have 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]]
like image 233
Merlin Avatar asked Aug 14 '11 14:08

Merlin


1 Answers

When you see a numpy array printed without commas, you are just looking at its string representation. If you want it printed with commas, you could 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]]
like image 73
unutbu Avatar answered Sep 30 '22 20:09

unutbu