I'm trying to learn arrays(with numpy) in python3 but i am not able to figure out how do i convert the elements of list to integer(in my case i have two dimentional array). I've tried two solutions that i found(its mentioned in the code) but it gives me error. Can someone help me? Thank you.
My main objective is to get inputs and store them like a matrix(for example like 3x3) so that later i can take any elements of the list and perform any operation on them.
[inline]
My main objective is to get inputs and store them like a matrix(for example like 3x3) so that later i can take any elements of the list and perform any operation on them.
[inline]
from numpy import array r,c=input("Number of row and cloumn:").split('x') r=int(r) c=int(c) m=[] for i in range(r): row_col=input("Row values:").split() m.append(row_col) m=list(map(int,m)) #not working # m=[int(i) for i in m] not working m=array(m) print(m) print(m[0:1,0:1])[/inline]
Output:TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
If i dont use the conversion( m=list(map(int,m)) ) then i getOutput:Number or row and cloumn:3x3
Row values:1 2 3
Row values:4 5 6
Row values:7 8 9
[['1' '2' '3']
['4' '5' '6']
['7' '8' '9']]
[['1']]
My expected output Output:Row values:1 2 3
Row values:4 5 6
Row values:7 8 9
[[1, 2, 3]
[4, 5, 6]
[7, 8, 9]]
[[1]]