File "D:\可信甄别\demo.py", line 32, in delet_changeqcar if (arr[10] != 0) and ((iloc[19] is None) or (iloc[20] is None)).any(): File "D:\可信甄别\venv\lib\site-packages\pandas\core\generic.py", line 1466, in __nonzero__ raise ValueError( ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
时间: 2023-06-27 17:01:09 浏览: 41
这个错误是因为你在使用 Pandas 的 `any()` 方法时,返回的结果是一个 Series,而不是一个单一的布尔值,导致 Python 不知道如何处理这个结果的真假值。你可以尝试使用 `all()` 或 `any().all()` 来解决这个问题。例如,将代码修改为:
```
if (arr[10] != 0) and ((iloc[19] is None) or (iloc[20] is None)).any().all():
```
或者:
```
if (arr[10] != 0) and ((iloc[19] is None) or (iloc[20] is None)).all():
```
都可以解决这个问题。具体哪种方法更适合取决于你的需求,如果你希望所有元素都为 True 才返回 True,那么使用 `all()`;如果你希望只要有一个元素为 True 就返回 True,那么使用 `any()`。
相关问题
File D:\Anaconda3\lib\site-packages\pandas\core\internals\managers.py:1724 in as_array arr = arr.astype(dtype, copy=False)
这段引用是关于pandas库中的数据类型转换的代码。其中,astype()方法可以将数据类型转换为指定的类型,但是在转换过程中可能会出现非有限值(NA或inf)无法转换为整数的情况,此时会抛出ValueError异常。另外,这段代码中的as_array()方法可以将数据块转换为数组,并且可以指定数据类型。在这里,as_array()方法中的astype()方法将数据类型转换为指定的类型,copy参数为False表示不进行复制操作,提高了代码的效率。
def data_generator(): for folder in os.listdir("D:/wjd"): for file in os.listdir("D:/wjd/"+folder): file_paths = glob.glob('D:/wjd/*.png') for file_path in file_paths: img = Image.open(file_path) img = img.resize((224, 224)) img_arr = np.array(img) img_tensor = tf.convert_to_tensor(img_arr) img_tensor = tf.expand_dims(img_tensor, axis=0) print(img_tensor.shape) print(img_tensor.shape) # 输出张量的形状,我感觉不对,我应该删除那两行代码啊
是的,你是正确的。在这个数据生成器函数中,`print(img_tensor.shape)` 这行代码是不必要的,因为它只是输出张量的形状,而不是将它们返回给调用者。因此,你可以将这两行代码删除,如下所示:
```python
def data_generator():
for folder in os.listdir("D:/wjd"):
for file in os.listdir("D:/wjd/"+folder):
file_paths = glob.glob('D:/wjd/*.png')
for file_path in file_paths:
img = Image.open(file_path)
img = img.resize((224, 224))
img_arr = np.array(img)
img_tensor = tf.convert_to_tensor(img_arr)
img_tensor = tf.expand_dims(img_tensor, axis=0)
yield img_tensor
```
这样修改后,这个函数将会生成一个张量序列,每个张量代表一个图片。你可以将这个函数作为参数传递给你的模型,用于训练和测试。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)