E.g:
a=[1,2,3] a.append(5)
In this case, the results of [1, 2, 3, 5]
a=[1,2,3] a.append([5])
In this case, the results of [1, 2, 3, [5]]
The result is no longer an array, but the list
Generate a multidimensional array using append:
import numpy as np a=[] for i in range(5): a.append([]) for j in range(5): a[i].append(i)
The results are as follows:
[[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]]
append () function in the list of python is a good use of