0

input

5 1 4 6 2 0 5 4 4 5 4

my code

import numpy as np
ARR = np.asarray( list(map(int, input().strip().split())) )
print(ARR)

output got

[5 1 4 6 2 0 5 4 4 5 4]

output expected

[5, 1, 4, 6, 2, 0, 5, 4, 4, 5, 4]

In particular, I either want to make a separated list, then convert to Numpy array, or do it all in one command line

5
  • When you print a numpy array, commas are omitted for readability. To get a string representation you want, you could simply use print(list(map(int, input().strip().split()))) or print(ARR.tolist()). Commented Jan 29, 2022 at 8:46
  • Also, possible duplicate of this question. I agree with the comment on the question that numpy.set_printoptions should support this. Commented Jan 29, 2022 at 8:59
  • thank you for linking that question, as i have found an answer through it, which is print(repr(ARR)) Commented Jan 29, 2022 at 9:06
  • Glad it helped. In this case, you should close the question as as duplicate. Commented Jan 29, 2022 at 9:12
  • 1
    since this is my first time ever on this site, I don't know how to close it Commented Jan 29, 2022 at 9:18

2 Answers 2

0

you can use list comprehension

import numpy as np
res = np.array([int(x) for x in input().split()])
print(res)
Sign up to request clarification or add additional context in comments.

1 Comment

This prints the same output OP gets in his example (without commas).
0

Ans was very simple split on spaces like split(' ')

ARR = np.asarray( list(map(int, input().strip().split(' '))))

Output

array([5, 6, 7, 8, 9, 5])

1 Comment

in print, this also gives the same result, which in non comma seperated

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.