'numpy.ndarray' object has no attribute 'sample'
时间: 2023-08-27 16:04:43 浏览: 570
将numpy.ndarray格式图像转化为_io.BufferedReader格式
The 'numpy.ndarray' object does not have a built-in 'sample' attribute. The 'sample' method is not available directly on numpy arrays. If you want to randomly sample elements from a numpy array, can use the 'random.choice' function from the numpy library. Here's an example:
```python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
sampled_element = np.random.choice(arr)
print(sampled_element)
```
This code will randomly select an element from the 'arr' numpy array and print it.
阅读全文