python - 'float' 对象没有属性 'round'
问题描述
我有一个代码如下所示:
history['test_acc'].append(results.history['val_dense_5_accuracy'][0])
然后我想打印如下:
print('Epoch: '+str(epoch)+'/'+str(epochs-1), 'Learning rate:',
'Test_acc:', history['test_acc'][-1].round(4),
'Test_loss:', history['test_loss'][-1].round(4))`
但在这一行:
'Test_acc:', history['test_acc'][-1].round(4)
我有这个错误:'float'对象没有属性'round'有什么问题?
解决方案
问题是这round
是一个内置的顶级函数,而不是float
s 上的方法。改变:
history['test_acc'][-1].round(4)
至:
round(history['test_acc'][-1], 4)
与test_loss
表达式类似的变化。
推荐阅读
- python - 如何为我在 PYTHON 中创建的模块创建帮助功能?
- r - 如何将列表中的 data.frames 合并/附加到一起并删除重复项
- import - 岩浆的内在定义
- c++ - 防止线程不必要的退出并使池保持活动状态
- abcpdf - ABCpdf 11.3 - 无法加载 html
- javascript - 复选框数组回答正确 r 不是(条件)
- reactjs - 反应 useState 数组更新
- configuration - Azure Synapse Studio 错误:无法访问外部表“dbo”,因为位置不存在或被另一个进程使用
- c# - 访问 C# 模板类中的成员变量
- docker - Next.js - Docker 环境变量没有被拾取