Python:DeprecationWarning:elementwise ==比较失败;将来会引发错误

编程入门 行业动态 更新时间:2024-10-27 18:30:12
本文介绍了Python:DeprecationWarning:elementwise ==比较失败;将来会引发错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在尝试udacity课程深度学习任务时,我遇到了一个问题,那就是将模型的预测与训练集的标签进行比较。我正在使用的数组具有以下形状:

While trying out the udacity course deep learning assignment, I came across a problem with comparing the predictions of my model with the labels of training set. The arrays I'm using have shapes:

训练集(200000,28,28)(200000,) 验证集(10000,28,28)(10000,) 测试集(10000,28,28)(10000,)

Training set (200000, 28, 28) (200000,) Validation set (10000, 28, 28) (10000,) Test set (10000, 28, 28) (10000,)

但是,使用函数检查准确性时:

However, when checking the accuracy with the function:

def accuracy(predictions, labels): return (100.0 * np.sum(np.argmax(predictions, 1) == np.argmax(labels, 1)) / predictions.shape[0])

给我:

C:\Users\Arslan\Anaconda3\lib\site-packages\ ipykernel_launcher.py:5:DeprecationWarning:elementwise ==比较失败;将来会出现错误。

C:\Users\Arslan\Anaconda3\lib\site-packages\ipykernel_launcher.py:5: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future. """

,它给出的所有数据集的准确度均为0%。

And it gives the accuracy as 0% for all datasets.

我认为我们不能使用'=='比较数组。我该如何以正确的方式比较数组?

I think we cannot compare the arrays using '=='. How could I compare the arrays in the right way instead?

推荐答案

我假设此表达式中发生错误:

I assume the error occurs in this expression:

np.sum(np.argmax(predictions, 1) == np.argmax(labels, 1))

您能告诉我们有关这两个数组的信息吗,预测,标签?常用的东西-dtype,形状,一些样本值。也许要多做一步,并显示每个 np.argmax(...)。

can you tell us something about the 2 arrays, predictions, labels? The usual stuff - dtype, shape, some sample values. Maybe go the extra step and show the np.argmax(...) for each.

在 numpy 您可以比较大小相同的数组,但是比较大小不匹配的数组变得更加挑剔:

In numpy you can compare arrays of the same size, but it has become pickier about comparing arrays that don't match in size:

In [522]: np.arange(10)==np.arange(5,15) Out[522]: array([False, False, False, False, False, False, False, False, False, False], dtype=bool) In [523]: np.arange(10)==np.arange(5,14) /usr/local/bin/ipython3:1: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future. #!/usr/bin/python3 Out[523]: False

更多推荐

Python:DeprecationWarning:elementwise ==比较失败;将来会引发错误

本文发布于:2023-11-25 18:30:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630861.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:将来   错误   Python   DeprecationWarning   elementwise

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!