TensorFlow-笔记

作者:chen_h
微信号 & QQ:862251340
微信公众号:coderpai


1.Tensorflow 数据类型

---------------------------------------------------------------
Data type (dtype)               Description
---------------------------------------------------------------

tf.float32                 32-bit floating point
tf.float64                 64-bit floating point
tf.int8                    8-bit signed integer
tf.int16                   16-bit signed integer
tf.int32                   32-bit signed integer
tf.int64                   64-bit signed integer
tf.uint8                   8-bit unsigned integer
tf.string                  String (as bytes array, not Unicode)
tf.bool                    Boolean
tf.complex64               Complex number, with 32-bit floating point real portion, and 32-bit floating point imaginary portion
tf.qint8                   8-bit signed integer (used in quantized Operations)
tf.qint32                  32-bit signed integer (used in quantized Operations)
tf.quint8                  8-bit unsigned integer (used in quantized Operations)


2.重载符号

TensorFlow重载了一些符号,使得表达更加清晰。

Unary operators


----------------------------------------------------------------------------------------
Operator               Related TensorFlow Operation    
----------------------------------------------------------------------------------------

-x                        tf.neg()                     
~x                        tf.logical_not() 
abs(x)                    tf.abs() 

Binary operators

----------------------------------------------------------------------------------
Operator               Related TensorFlow Operation
-----------------------------------------------------------------------------------

x + y                            tf.add()
x - y                            tf.sub()  
x * y                            tf.mul()  
x / y                            (Python 2) tf.div()  
x / y                            (Python 3) tf.truediv()  
x // y                           (Python 3) tf.floordiv()  
x % y                            tf.mod()  
x ** y                           tf.pow()  
x < y                            tf.less()  
x <=    y                        tf.less_equal()  
x > y                            tf.greater()  
x >= y                           tf.greater_equal()  
x & y                            tf.logical_and()  
x | y                            tf.logical_or()  
x ^ y                            tf.logical_xor()  

3.图和会话

# 一般我们写程序的时候,都会指定是哪个图
# 得到默认图
default_graph = tf.get_default_graph()
g = tf.Graph()

with g.as_default():
  a = tf.constant(2)
  b = tf.constant(4)
  c = tf.add(a,b)

with default_graph.as_default():
  aa = tf.constant(4)
  bb = tf.constant(8)
  cc = tf.add(aa, bb)

sess = tf.Session(graph = g)
# 这个语句是对的,因为会话里面的图是g
print(sess.run(c))
# 这个语句是错误的,因为只有图g能执行,而图default_graph不行,因为不在会话里
print(sess.run(cc))

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值