How to convert a 2D list to 2D numpy array (matrix) in Python

2 Answers

0 votes
import numpy as np

lst = [[1,2,3], [4,5,6], [7,8,9]]

arr = np.array(lst)

print(arr)





'''
run:

[[1 2 3]
 [4 5 6]
 [7 8 9]]

'''

 



answered Feb 23, 2023 by avibootz
0 votes
import numpy as np

lst = [[1,2,3], [4,5,6], [7,8,9]]

arr = np.matrix(lst)

print(arr)





'''
run:

[[1 2 3]
 [4 5 6]
 [7 8 9]]

'''

 



answered Feb 23, 2023 by avibootz
...