'numpy.ndarray' object has no attribute 'count'. Did you mean: 'conj'?
时间: 2023-09-21 20:11:12 浏览: 128
将numpy.ndarray格式图像转化为_io.BufferedReader格式
The error message suggests that you are trying to call the `count` attribute on a NumPy ndarray, which does not exist.
The `count` attribute is not a built-in attribute for NumPy ndarrays. If you're looking to count the number of occurrences of a specific value within the array, you can use the `np.count_nonzero` function. For example, if you want to count the number of occurrences of the value `0` in an array called `my_array`, you can use the following code:
```
import numpy as np
my_array = np.array([0, 1, 2, 0, 3, 0, 4])
count = np.count_nonzero(my_array == 0)
print(count) # Output: 3
```
This code creates an array `my_array` with some values and then uses the `np.count_nonzero` function to count the number of times `0` appears in the array.
阅读全文