python计算sinx的程序_Python Tensorflow sin()用法及代码示例
Tensorflow是Google开发的开源机器学习库。它的应用之一是开发深度神经网络。
模块tensorflow.math为许多基本的数学运算提供支持。功能tf.sin()[别名tf.math.sin]支持Tensorflow中的正弦函数。它期望输入为弧度形式,并且输出范围为[-1,1]。输入类型为张量,如果输入包含多个元素,则将按元素计算正弦。
用法:tf.sin(x, name=None) or tf.math.sin(x, name=None)
参数:
x:以下任何类型的张量:float16,float32,float64,complex64或complex128。
name(可选):操作的名称。
返回类型:与x具有相同类型的张量。
代码1:
# Importing the Tensorflow library
import tensorflow as tf
# A constant vector of size 6
a = tf.constant([1.0, -0.5, 3.4, -2.1, 0.0, -6.5], dtype = tf.float32)
# Applying the sin function and
# storing the result in 'b'
b = tf.sin(a, name ='sin')
# Initiating a Tensorflow session
with tf.Session() as sess:
print('Input type:', a)
print('Input:', sess.run(a))
print('Return type:', b)
print('Output:', sess.run(b))
输出:
Input type:Tensor("Const_1:0", shape=(6, ), dtype=float32)
Input:[ 1. -0.5 3.4000001 -2.0999999 0. -6.5 ]
Return type:Tensor("sin_0:0", shape=(6, ), dtype=float32)
Output:[ 0.84147096 -0.47942555 -0.25554121 -0.86320943 0. -0.21511999]
代码2:可视化
# Importing the Tensorflow library
import tensorflow as tf
# Importing the NumPy library
import numpy as np
# Importing the matplotlib.pylot function
import matplotlib.pyplot as plt
# A vector of size 15 with values from -5 to 5
a = np.linspace(-5, 5, 15)
# Applying the sigmoid function and
# storing the result in 'b'
b = tf.sin(a, name ='sin')
# Initiating a Tensorflow session
with tf.Session() as sess:
print('Input:', a)
print('Output:', sess.run(b))
plt.plot(a, sess.run(b), color = 'red', marker = "o")
plt.title("tensorflow.sin")
plt.xlabel("X")
plt.ylabel("Y")
plt.show()
输出:
Input:[-5. -4.28571429 -3.57142857 -2.85714286 -2.14285714 -1.42857143
-0.71428571 0. 0.71428571 1.42857143 2.14285714 2.85714286
3.57142857 4.28571429 5. ]
Output:[ 0.95892427 0.91034694 0.41672165 -0.2806294 -0.84078711 -0.98990308
-0.6550779 0. 0.6550779 0.98990308 0.84078711 0.2806294
-0.41672165 -0.91034694 -0.95892427]
python计算sinx的程序_Python Tensorflow sin()用法及代码示例相关推荐
- python cos函数_Python Tensorflow cos()用法及代码示例
Tensorflow是Google开发的开源机器学习库.它的应用之一是开发深度神经网络. 模块tensorflow.math为许多基本的数学运算提供支持.功能tf.cos()[别名tf.math.co ...
- python中sinh是什么_Python PyTorch sinh()用法及代码示例
PyTorch是由Facebook开发的开源机器学习库.它用于深度神经网络和自然语言处理. 功能torch.sinh()为PyTorch中的双曲正弦函数提供支持.它期望以弧度形式输入.输入类型为张量, ...
- python中tan怎么表示_Python numpy.tan()用法及代码示例
numpy.tan(array [,out])= ufunc'tan'):此数学函数可帮助用户计算所有x(作为数组元素)的三角切线. 参数: array :[array_like]elements a ...
- python中cos怎么表示_Python numpy.cos()用法及代码示例
numpy.cos(x [,out])= ufunc'cos'):此数学函数可帮助用户计算所有x(作为数组元素)的三角余弦. 参数: array :[array_like]elements are i ...
- python中ln怎么写_Python Decimal ln()用法及代码示例
Decimal#ln():ln()是一个Decimal类方法,它返回Decimal值的自然(对数e)对数. 用法:Decimal.ln() 参数:十进制值 返回:十进制值的自然(以e为底)对数. 代码 ...
- python画折线图虚线_python绘制简单折线图代码示例
1.画最简单的直线图 代码如下: import numpy as np import matplotlib.pyplot as plt x=[0,1] y=[0,1] plt.figure() plt ...
- python的datetime举例_Python datetime.timedelta()用法及代码示例
Python timedelta()函数存在于datetime库中,该函数通常用于计算日期差,也可以用于Python中的日期操作.这是执行日期操作的最简单方法之一. 用法: datetime.time ...
- python中mean的用法_Python statistics mean()用法及代码示例
先决条件:统计函数简介 在数据分析和统计方面,Python是一种非常流行的语言.幸运的是,Python3提供了statistics模块,它具有非常有用的功能,例如mean(),median(),mod ...
- python中pop用法_Python dict pop()用法及代码示例
Python语言为几乎所有容器(无论是列表容器还是集合容器)指定了pop().这篇特别的文章着重说明Python词典提供的pop()方法.这种方法对于经常处理字典的程序员很有用. 用法:dict.po ...
- python中pop用法_Python Set pop()用法及代码示例
Python的这种内置功能有助于在实现Stack时从集合中弹出元素,就像概念中使用的原理一样.此方法从集合中删除随机元素,然后返回删除的元素.与之不同的是,堆栈中会弹出一个随机元素. 用法: # Po ...
最新文章
- 字符串操作练习:星座、凯撒密码、99乘法表、词频统计预处理
- LearningR-XML
- JVM 内存模型:运行时常量池
- python中删除字典中的某个元素_python怎样删除字典中的元素
- 前端学习(493):script之延迟脚本和异步脚本
- 炸窝Vector简介
- Git命令:常用Git命令集合
- ISTQB高级国际认证试题及答案(一)
- 这些云计算网络安全知识,你不得不知
- echarts x轴加箭头,ECharts X轴(xAxis)
- SpringBoot整合easyexcel进行excel报表导入导出
- SQL语言基础-数据查询
- 地图标注不完整图片_“地图帝”不规范使用图件之Anton Balazh作品介绍
- android开发 自我优势_安卓程序员自我评价
- word快捷键复制粘贴无法使用
- 等差数列计算机函数公式大全,等差数列公式大全
- 态密度的Delta函数公式以及范霍夫奇点
- Android流量统计
- PMP笔记:Line Manager与Functional Manager
- 【Javaweb】【答卷】萌狼蓝天大二上学期期末Javaweb考试复习卷(一)