The list in python is a built-in data type of python, the data types in the list do not have to be the same , and the data types in the array must all be the same .
The array encapsulated in numpy has a very powerful function, and the same data type is stored in it.
The list code is as follows:
a=[[1,2],[1,2]] # two-dimensional list print (a) b=a[1][1] print(b)
operation result:
[[1, 2], [1, 2]]
2
Note: The method to read the elements of the two-dimensional list in the above code is a[1][1], not a[1,1]
The array code is as follows:
import numpy as np a = np.array([[1,2],[1,2]]) #Convert the list to array type print (a) b=a[1][1] print(b) c=a[1,1] print(c)
operation result:
[[1 2]
[1 2]]
2
2
Note: After converting the list to an array type, the method to read the elements in the two-dimensional array can be a[1][1] or a[1,1]. But the previous list can only be a[1][1]