Python:DeprecationWarning:elementwise ==比较失败;将来会引发错误 [英] Python: DeprecationWarning: elementwise == comparison failed; this will raise an error in the future
问题描述
在尝试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 ==比较失败;将来会引发错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!