Difference between Python array and list

The difference between Python arrays and lists:
1. Numpy is a library dedicated to data processing, which can well support some mathematical operations, while lists are more troublesome for mathematical operations, for example:

a = [1, 2, 3, 4]
b = np.array([1, 2, 3, 4])
c = a * 2
d = b * 2
print(c)
print(d)

Output result:
[1, 2, 3, 4, 1, 2, 3, 4]
[2 4 6 8]
2. The list stores one-dimensional data, while the array can store multi-dimensional data. E.g:

e = [[1, 2], [3, 4], [5, 6]]
f = np.array([12],[3, 4], [5, 6] ])
print(e)
print(f)

The output result is:
[[1, 2], [3, 4], [5, 6]]
[[1 2]
[3 4]
[5 6]]

Guess you like

Origin blog.csdn.net/Wilburzzz/article/details/107645533