AttributeError: 'numpy.ndarray' object has no attribute 'extend'
时间: 2023-09-20 20:08:41 浏览: 379
This error occurs when trying to use the extend method on a NumPy array. The extend method is not supported by NumPy arrays.
To add elements to a NumPy array, you can use the concatenate method or the append method. The concatenate method allows you to combine two or more arrays, while the append method allows you to add a single element to the end of the array.
Here is an example of using the concatenate method:
```
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
arr3 = np.concatenate([arr1, arr2])
print(arr3) # Output: [1 2 3 4 5 6]
```
Here is an example of using the append method:
```
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.append(arr1, 4)
print(arr2) # Output: [1 2 3 4]
```
Note that the append method returns a new array with the appended element, so you need to assign it to a new variable or to the original array to keep the changes.
阅读全文