TensorFlow是Google设计的开源python库,用于开发机器学习模型和深度学习神经网络。 round()用于查找x的逐元素最接近的整数。

用法:tf.math.round(x, name)

参数:

x:它是输入张量。此张量的允许dtype是bfloat16,half,float32,float64。

name(optional):它定义了操作的名称。

返回值:

它返回与x相同dtype的张量。

范例1:

Python3

# Importing the library

import tensorflow as tf

# Initializing the input tensor

a = tf.constant([.2, 1.6, 3.7, 1], dtype = tf.float64)

# Printing the input tensor

print('a:', a)

# Calculating result

res = tf.math.round(a)

# Printing the result

print('Result:', res)

输出:

a: tf.Tensor([0.2 1.6 3.7 1. ], shape=(4, ), dtype=float64)

Result: tf.Tensor([0. 2. 4. 1.], shape=(4, ), dtype=float64)

范例2:四舍五入到一半。

Python3

# importing the library

import tensorflow as tf

# Initializing the input tensor

a = tf.constant([2.5, 5.5, 1.5, 6.5], dtype = tf.float64)

# Printing the input tensor

print('a:', a)

# Calculating result

res = tf.math.round(a)

# Printing the result

print('Result:', res)

输出:

a: tf.Tensor([2.5 5.5 1.5 6.5], shape=(4, ), dtype=float64)

Result: tf.Tensor([2. 6. 2. 6.], shape=(4, ), dtype=float64)

pythonmath库round计算_Python tensorflow.math.round()用法及代码示例相关推荐

  1. python annotate函数_Python Matplotlib.pyplot.annotate()用法及代码示例

    Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展. Pyplot是Matplotlib模块的基于状态的接口,该模块提供了MATLAB-like接口. matplotli ...

  2. python function gamma_Python math gamma()用法及代码示例

    Python用其语言允许进行各种数学运算,这在科学领域具有多种应用.这样的Python产品之一就是内置的gamma()函数,该函数以数字方式计算函数中传递的数字的伽玛值. 用法:math.gamma( ...

  3. python datetime timedelta函数_Python Pandas DatetimeIndex.to_perioddelta()用法及代码示例

    Python是进行数据分析的一种出色语言,主要是因为以数据为中心的python软件包具有奇妙的生态系统. Pandas是其中的一种,使导入和分析数据更加容易. Pandas DatetimeIndex ...

  4. python 希尔伯特变换_python scipy signal.hilbert用法及代码示例

    使用希尔伯特变换来计算分析信号. 默认情况下,转换是沿着最后一个轴完成的. 参数: x:array_like信号数据.必须是真实的. N:int, 可选参数傅立叶分量的数量.默认:x.shape[ax ...

  5. java中decrement,Java Math decrementExact()用法及代码示例

    java.strictmath.lang.decrementExact()是java中的内置函数,该函数返回减1的参数,如果结果溢出指定的数据类型long或int,则抛出异常,具体取决于在方法参数上使 ...

  6. math.hypot java_Java Math hypot()用法及代码示例

    java.lang.Math.hypot()函数是Java中的内置数学函数,可返回欧几里得范数, .函数返回sqrt(x2+ y2),而不会出现中间上溢或下溢. 如果任何一个参数都是无限大,则结果为正 ...

  7. java中div的用法,Java Math floorDiv()用法及代码示例

    java.lang.Math.floorDiv()是java中的内置数学函数,它返回小于或等于代数商的最大(最接近正无穷大)int值.由于floorDiv()是静态的,因此不需要创建对象. 用法: p ...

  8. python可以构建sem模型_Python Pandas Series.sem()用法及代码示例

    Pandas 系列是带有轴标签的一维ndarray.标签不必是唯一的,但必须是可哈希的类型.该对象同时支持基于整数和基于标签的索引,并提供了许多方法来执行涉及索引的操作. Pandas Series. ...

  9. python3 math module_Python math hypot()用法及代码示例

    hypot()函数是Python中的内置数学函数,可返回欧几里得范数, . 用法: hypot(x, y) 参数: x and y are numerical values 返回值: Returns ...

最新文章

  1. “Python来玩微信跳一跳”教程(问题总结)
  2. matlab中利用princomp实现PCA降维
  3. 激动,新手第一次小试oracle的存储过程
  4. dojo/request模块整体架构解析
  5. [ BZOJ 2160 ] 拉拉队排练
  6. 当自动化遇见数字化——德资企业儒拉玛特的数字化实践
  7. 简记GAN网络的loss
  8. UE4蓝图 绑定输入
  9. BurpSuite 1.6~2.x版本汉化版工具
  10. Android 模拟吹气实现吹风车效果
  11. android开发工具 go,轻松搭建基于go1.5开发Android应用的环境 | Go语言中文网 | Golang中文社区 | Golang中国...
  12. android so 瘦身,Android APK 瘦身实践
  13. cpu满载寿命_CPU的使用寿命大概有多少年,多久迭代一次为佳?
  14. 7个实用的Python自动化测试框架
  15. 联想开机启动项按哪个_联想笔记本按哪个键进入u盘启动
  16. route命令添加永久路由
  17. 【计算机组成原理-chapter1】计算机组成原理概述
  18. Vue + ElementUI 仿视频网站&抖音创作者平台
  19. 移动端大规模草渲染的实现(精简版)
  20. 程序员是青春饭吗?30岁后的发展方向和突破

热门文章

  1. 【计算机基础】03-Word知识
  2. qq邮箱如何在win10邮箱连接到服务器,Win10系统自带Mail应用添加QQ邮箱的方法
  3. 使用 NoSQL 数据库提供云级别数据可伸缩性
  4. 转自博客园:http://www.cnblogs.com/txw1958/p/wechat-tutorial.html
  5. 计算机论文致谢词范文500字,大专论文的结尾致谢500字(论文的致谢语)
  6. html报告致谢,论文致谢优秀范文(精选10篇)
  7. RAC 网络心跳 磁盘心跳 本地心跳 控制文件磁盘心跳
  8. 决策树ID3代码(Python)
  9. 开启阿里云80端口:如何配置阿里云服务器安全组
  10. 算法设计例题分析 食物链