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))) #输出结果为3tf.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))) #输出结果为10tf.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))) #输出结果为2tf.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))) #输出结果为1tf.abs(x,name=None) #求绝对值
import tensorflow as tf; A=-5 B=2 with tf.Session() as sess: print(sess.run(tf.abs(A))) #输出结果为5tf.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))) #输出结果为-2tf.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))) #输出结果为1tf.reciprocal(x,name=None) #取反运算
import tensorflow as tf; A=-5 B=1/2 with tf.Session() as sess: print(sess.run(tf.reciprocal(B))) #输出结果为2tf.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.25tf.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))) #输出结果为3tf.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]
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: java字符串大小写转化
- 下一篇: tensorflow编程: Math