python中mean()函数的使用

import numpy as np
preds = np.array([[1],
                  [2],
                  [0],
                  [4]])
labels = np.array([[1],
                   [2],
                   [3],
                   [0]])
for i in range(preds.size):
    if (preds[i]==labels[i]):
        print(i)
        
acc = (preds == labels)
acc1 = (preds == labels).mean()
print(acc)
print(acc1)
D:\ProgramData\Anaconda3\envs\jointBert\python.exe E:/github/2020.03/Bert-SF-ID/test.py
0
1
[[ True]
 [ True]
 [False]
 [False]]
0.5
发布了41 篇原创文章 · 获赞 44 · 访问量 7657

猜你喜欢

转载自blog.csdn.net/tailonh/article/details/105046610