Tenosrflow中基本算术运算函数


Tensorflow中基本算术运算函数如下:

tf.add(x,y,name=None)     # 求和运算;

import  tensorflow as tf;
A = 5
B = 2
with tf.Session() as sess:
            print(sess.run(tf.add(A,B)))   #输出结果为7;
tf.subtract(x,y,name=None)     # 减法运算  ,tensorflow更新到1.0后,函数名发生了变化,之前函数名为tf.sub(x,y,name=None)

import  tensorflow as tf;
A = 5
B = 2
with tf.Session() as sess:
            print(sess.run(tf.subtract(A,B)))         #输出结果为3
tf.multiply(x,y,name=None)     #乘法运算   ,之前函数名为tf.mul(x,y,name=None)

import   tensorflow as tf;
A=5
B=2
with tf.Session() as sess:
                  print(sess.run(tf.multiply(A,B)))   #输出结果为10
tf.div(x,y,name=None)    #除法运算 

import tensorflow as tf;

A=5
B=2
with tf.Session() as sess:
    print(sess.run(tf.div(A,B)))  #输出结果为2
tf.mod(x,y,name=None) # 取模运算

import tensorflow as tf;
A=5
B=2
with tf.Session() as sess:
    print(sess.run(tf.mod(A,B)))   #输出结果为1
tf.abs(x,name=None) #求绝对值

import tensorflow as tf;
A=-5
B=2
with tf.Session() as sess:
   print(sess.run(tf.abs(A)))  #输出结果为5
tf. negative(x,name=None) #取负运算(y=-x)
import tensorflow as tf;
A=-5
B=2
with tf.Session() as sess:
   print(sess.run(tf.negative(A)))   #输出结果为5
   print(sess.run(tf.negative(B)))   #输出结果为-2
tf.sign(x,name=None)   #返回符合 x大于0,则返回1,小于0,则返回-1;

import tensorflow as tf;
A=-5
B=2
with tf.Session() as sess:
   print(sess.run(tf.sign(A)))  #输出结果为-1
   print(sess.run(tf.sign(B)))  #输出结果为1
tf.reciprocal(x,name=None)   #取反运算

import tensorflow as tf;
A=-5
B=1/2
with tf.Session() as sess:
    print(sess.run(tf.reciprocal(B)))  #输出结果为2
tf.square(x,name=None)     #计算平方

import tensorflow as tf;
A=-5
B=1/2
with tf.Session() as sess:
    print(sess.run(tf.square(B)))#输出结果为0.25
tf.round(x,name=None)  #舍入最接近的整数

import tensorflow as tf;
A=-5.1
B=2.6
with tf.Session() as sess:
    print(sess.run(tf.round(A)))  #输出结果为-5
    print(sess.run(tf.round(B)))  #输出结果为3
tf.pow(x,y,name=None)  #幂次方

import tensorflow as tf;
A=[2,3]
B=2
with tf.Session() as sess:
    print(sess.run(tf.pow(A,B))) #输出结果为[4,9]














  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值