[TensorFlow系列-6]:TensorFlow基础 - 张量的三角函数运算

 作者主页(文火冰糖的硅基工坊):https://blog.csdn.net/HiWangWenBing

本文网址:https://blog.csdn.net/HiWangWenBing/article/details/119619592


目录

第1部分:Tensor运算概述

1.1 概述

1.2 运算分类

1.3  “in place“运算 

1.4 Tensor的广播机制: 不同维度的tensor实例运算

1.5 环境准备

1.6 三角函数概述

第2部分 正弦运算

第3部分 余弦运算



第1部分:Tensor运算概述

1.1 概述

深度学习框架Tensorflow提供了大量的张量运算,基本上可以对标Numpy多维数组的运算,以支持对张量的各种复杂的运算。

这些操作运算中大多是对数组中每个元素执行相同的函数运算,并获得每个元素函数运算的结果序列,这些序列生成一个新的同维度的数组。

https://tensorflow.google.cn/tutorials/quickstart/beginner?hl=zh-cn

1.2 运算分类

(1)算术运算:加、减、系数乘、系数除

(2)函数运算:sin,cos

(3)取整运算:上取整、下取整

(4)统计运算:最大值、最小值、均值

(5)线性代数运

1.3  “in place“运算 

NA

1.4 Tensor的广播机制: 不同维度的tensor实例运算

1.5 环境准备

import numpy as np
import tensorflow as tf
print("hello world")
print("tensorflow version:", tf.__version__)

1.6 三角函数概述

Tensor提供了标准的三角函数:sin()、cos()、tan()。

tf.cos(x, name=None)三角函数cosine
tf.sin(x, name=None)三角函数sine
tf.tan(x, name=None)三角函数tan
tf.atan(x, name=None)三角函数ctan

说明:如果把数组A作为x轴数据,把三角函数的运算结果B作为y轴数据,并送给画图工具,就可以得到三角函数的图像。

  • abs:绝对值
  • cosh:双曲余弦函数

第2部分 正弦运算

#实例
a = tf.constant([0,30,45,60,90],dtype=tf.float32)
print(a)

print ('\n不同角度的正弦值:')
# 通过乘 pi/180 转化为弧度  
print (tf.sin(a*np.pi/180))
输出结果:

tf.Tensor([ 0. 30. 45. 60. 90.], shape=(5,), dtype=float32)

不同角度的正弦值:
tf.Tensor([0.         0.5        0.70710677 0.86602545 1.        ], shape=(5,), dtype=float32)

第3部分 余弦运算

#实例
a = tf.constant([0.,30.,45.,60.,90.])
print(a)

print ('\n不同角度的余弦值:')
# 通过乘 pi/180 转化为弧度  
print (tf.cos(a*np.pi/180))
print ('\n')
输出结果:

tf.Tensor([ 0. 30. 45. 60. 90.], shape=(5,), dtype=float32)

不同角度的余弦值:
tf.Tensor(
[ 1.0000000e+00  8.6602539e-01  7.0710677e-01  4.9999997e-01
 -4.3711388e-08], shape=(5,), dtype=float32)

arcsin,arccos,和 arctan 函数返回给定角度的 sin,cos 和 tan 的反三角函数。

这些函数的结果可以通过 numpy.degrees() 函数将弧度转换为角度。



作者主页(文火冰糖的硅基工坊):https://blog.csdn.net/HiWangWenBing

本文网址:https://blog.csdn.net/HiWangWenBing/article/details/119619592

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

文火冰糖的硅基工坊

你的鼓励是我前进的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值