The input data in a two dimensional array in python?

Given matrix as a sequence of lines, ending with a line containing only the string "end" (without the quotes)for example:
21 312 21
25 412 13
end
how to capture it in a two-dimensional array a?
April 3rd 20 at 18:50
2 answers
April 3rd 20 at 18:52
To read the string, if string equal to 'end' to finish, or to split the line apart on the space bar to place the numbers in the list of lists.
April 3rd 20 at 18:54
an example of a two-dimensional array
str1 = "'21 312 21
25 412 13"'

arr = [x.split(' ') for x in str1.split('\n')]
print(arr)

[['21', '312', '21'], ['25', '412', '13']]

to convert the array values to numbers - that will be your homework
But the end what happened? You skillfully changed the formulation of the problem, pleasure to watch. - Marlene.Hyatt66 commented on April 3rd 20 at 18:57
@naomie83, the big problem dataset to take to 'end'?
str2 = "'21 312 21
25 412 13
end"'

[x.split(' ') for x in str2.split('end')[0].split('\n') if len(x)>0]


[['21', '312', '21'], ['25', '412', '13']] - reggie.OKon commented on April 3rd 20 at 19:00

Find more questions by tags PythonArrays