tensorflow 复合逻辑‘且’和‘或’的实现
2017-10-12 11:54
856 查看
import tensorflow as tf n1 = tf.constant(2) n2 = tf.constant(3) n3 = tf.constant(4) n4 = tf.constant(5) def true_fn1(): return tf.constant(11) def false_fn1(): return tf.constant(22) def true_fn(): return tf.cond(n3<n4,true_fn1,false_fn1) def false_fn(): return tf.constant(33) r = tf.cond(n1<n2,true_fn,false_fn) sess = tf.Session() print(sess.run(r))
print结果11
相当于实现了
if n1<n2 and n3<n4:
后来发现,用
&和
|就行了
import tensorflow as tf n1 = tf.constant(True,tf.bool) n2 = tf.constant(False,tf.bool) r1 = n1 | n2 r2 = n1 & n2 sess = tf.Session() print(sess.run(r1)) print(sess.run(r2))
import tensorflow as tf n1 = tf.constant(1)>tf.constant(0) n2 = tf.constant(1)<tf.constant(0) r1 = n1 | n2 r2 = n1 & n2 sess = tf.Session() print(sess.run(r1)) print(sess.run(r2))
相关文章推荐
- tensorflow实现逻辑回归,在kaggle《泰坦尼克》训练并测试准确率
- Tensorflow 实现稠密输入数据的逻辑回归二分类
- 利用tensorflow一步一步实现基于MNIST 数据集进行手写数字识别的神经网络,逻辑回归
- Tensorflow学习之逻辑回归的实现
- 10分钟搞懂Tensorflow 逻辑回归实现手写识别
- Logistic Regression 逻辑回归,Tensorflow源码实现
- 利用TensorFlow实现多元逻辑回归
- 10分钟搞懂Tensorflow 逻辑回归实现手写识别
- Tensorflow实现逻辑分类器
- 详解用TensorFlow实现逻辑回归算法
- Tensorflow学习笔记(三)——用Tensorflow实现线性回归和逻辑回归
- 10分钟搞懂Tensorflow 逻辑回归实现手写识别
- tensorflow实现简单逻辑回归
- 代码,逻辑回归(logistic_regression)实现mnist分类(TensorFlow实现)
- tensorflow实现对tensor中各个元素求逻辑‘与’
- 逻辑回归之tensorflow实现
- Python实现一个简单的购物车逻辑
- 如何用 TensorFlow 实现 GAN
- 用简单的代码逻辑实现三级缓存图片
- 用PHP+MySQL实现12306购票和退票以及余票查询逻辑