I have Numpy array:
我有Numpy数组:
[[12 13 14],[15 16 17],[18 19 20]]
How do I get this
我怎么得到这个
[[12, 13, 14], [15, 16, 17],[18 ,19, 20]]
1 个解决方案
#1
13
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:
当你看到一个没有逗号的numpy数组时,你只是看它的字符串表示。如果你想用逗号打印,可以将它转换为Python列表:
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]]
#1
13
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:
当你看到一个没有逗号的numpy数组时,你只是看它的字符串表示。如果你想用逗号打印,可以将它转换为Python列表:
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]]