# Tensorflow | 基本函数介绍

• 我的版本：anaconda 4.2 tensorflow 0.12.1
• 若是你不知道如何在windows下安装tensorflow，可以依照我的博客：http://blog.csdn.net/xxzhangx/article/details/54379255 ，遵循上面的顺序来做；若是安装过程中遇到问题，可以在博客下方留言，看到后会及时回答。

### 数值乘法mul

```import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
y = tf.mul(a, b)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 3, b: 3}))```

```import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 3, b: 3}))```

### 数值减法sub

```import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
y = tf.sub(a, b)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 3, b: 3}))```

### 数值除法div

```import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
y = tf.div(a, b)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 3, b: 3}))```

### 数值取模mod

```import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
y = tf.mod(a, b)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 3, b: 3}))```

### 数值绝对值abs

```import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
y = tf.abs(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3}))```

### 数值非负值neg

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.neg(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3}))```

### 数值符号函数sign

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.neg(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3}))```

### 数值符号函数sign

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.sign(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3}))```

### 数值倒数inv

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.sign(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3}))```

### 数值平方square

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.square(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3}))```

### 数值最近的整数round

```import tensorflow as tf
y = tf.round(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3.6}))```

```import tensorflow as tf
y = tf.round(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3.3}))```

### 数值平方根sqrt

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.sqrt(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 4}))```

### 数值幂次pow

```import tensorflow as tf
a = tf.placeholder(tf.float64)
b = tf.placeholder(tf.float64)
y = tf.pow(a, b)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 2, b: 3}))```

### 数值最近的整数exp

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.exp(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 2}))```

### 数值取对数log

```import tensorflow as tf
a = tf.placeholder(tf.float32)
y = tf.log(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 2}))```

### 数值取最大值maximum

```import tensorflow as tf
a = tf.placeholder(tf.float32)
b = tf.placeholder(tf.float32)
y = tf.maximum(a,b)
sess = tf.Session()
print (sess.run(y, feed_dict={a: -3.6,b: 2}))```

### 数值最小值minimum

```import tensorflow as tf
a = tf.placeholder(tf.float64)
b = tf.placeholder(tf.float64)
y = tf.minimum(a, b)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 2, b: 3}))```

### 数值余弦函数cos

```import tensorflow as tf
a = tf.placeholder(tf.float64)
y = tf.cos(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 2}))```

### 数值正弦函数sin

```import tensorflow as tf
a = tf.placeholder(tf.float64)
y = tf.sin(a)
sess = tf.Session()
print (sess.run(y, feed_dict={a: 2}))```

0 条评论

• ### Tensorflow | 函数名字的更新

上面列的是常见的变化。更多的了解，请看https://www.tensorflow.org/install/migration 官网给出了tensorflow更...

• ### Tensorflow | 斯坦福cs20si | lecture1

上图的代码存在问题，目前不知道怎么修改。若是有朋友有修改方案，请在下方留言，谢谢！

• ### win10 tensorflow笔记2 MNIST机器学习入门

这里跟官方有两处不同 1：第1行代码原文是import input_data这里的input_data是无法直接导入的。需要给出具体路径from tensor...

• ### TensorFlow2.X学习笔记(1)--TensorFlow核心概念

TensorFlow™ 是一个采用 数据流图（data flow graphs），用于数值计算的开源软件库。节点（Nodes）在图中表示数学操作，图中的线（e...

• ### TensorFlow2.X学习笔记(3)--TensorFlow低阶API之张量

TensorFlow提供的方法比numpy更全面，运算速度更快，如果需要的话，还可以使用GPU进行加速。

• ### TensorFlow2.X学习笔记(4)--TensorFlow低阶API之AutoGraph相关研究

而Autograph机制可以将动态图转换成静态计算图，兼收执行效率和编码效率之利。