5

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]]
2
  • i don't understand what you want, but does this help: str(numpy.ones((2,3))).replace('array(', '').replace(')', '') (if so, that has nothing to do with parsing). Commented Aug 14, 2011 at 14:58
  • Can you tell mehow you ended up assigning the value [[12 13 14] [15 16 17] [18 19 20]] to a variable ?I am curious Commented Aug 14, 2011 at 15:36

1 Answer 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:

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]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.