'numpy.ndarray' object has no attribute 'ceil'
时间: 2023-09-19 21:10:16 浏览: 112
This error occurs when you try to call the `ceil()` function on a NumPy array, but the function is not defined for arrays.
The `ceil()` function is defined for individual elements of an array, but not for the entire array. To apply the `ceil()` function to all elements of the array, you can use the `numpy.ceil()` function instead.
Here is an example:
```python
import numpy as np
arr = np.array([1.2, 2.5, 3.8])
# arr.ceil() # This will raise an AttributeError
arr_ceil = np.ceil(arr)
print(arr_ceil) # Output: [2. 3. 4.]
```
In this example, calling `arr.ceil()` raises an AttributeError because the `ceil()` function is not defined for the array itself. Instead, we use the `numpy.ceil()` function to apply the `ceil()` function to all elements of the array, and store the result in a new array `arr_ceil`.
阅读全文