Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7192659
  • 博文数量: 510
  • 博客积分: 12019
  • 博客等级: 上将
  • 技术积分: 6836
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-01 16:46
文章分类

全部博文(510)

文章存档

2022年(2)

2021年(6)

2020年(59)

2019年(4)

2018年(10)

2017年(5)

2016年(2)

2015年(4)

2014年(4)

2013年(16)

2012年(47)

2011年(65)

2010年(46)

2009年(34)

2008年(52)

2007年(52)

2006年(80)

2005年(22)

分类: Python/Ruby

2020-04-14 08:28:43

注意区别和numpy,tf中shape-1不能用于维度。None 常量和变量中不能用,只能用在占位符
但是tf.reshape可以用-1,表示不确定多个,比如
x5 = tf.constant(0,shape=[2,3,5], dtype=tf.float32)
x6 = tf.reshape(x5,[-1,5])


#标量
x = tf.constant(-3.0, dtype=tf.float32)
print x
Tensor("Const:0", shape=(), dtype=float32)

#标量
x1 = tf.constant(-3.0,shape=[], dtype=tf.float32)
print x1
Tensor("Const_1:0", shape=(), dtype=float32)

#向量
x2 = tf.constant(-1,shape=[4], dtype=tf.float32)
print x2
Tensor("Const_2:0", shape=(4,), dtype=float32)

#向量
x4 = tf.constant(-1,shape=[4,], dtype=tf.float32)
print x4
Tensor("Const_3:0", shape=(4,), dtype=float32)
注意向量不可表示为shape=[,4]

#矩阵
x5 = tf.constant(-1,shape=[4,5], dtype=tf.float32)
print x5
Tensor("Const_4:0", shape=(4, 5), dtype=float32)


#变量标量
v1 =  tf.get_variable("aa", [], initializer=tf.truncated_normal_initializer(stddev=0.1))
print v1




#变量向量
v2 =  tf.get_variable("aa2", [2], initializer=tf.truncated_normal_initializer(stddev=0.1))
print v2




#变量向量
v3 =  tf.get_variable("aa3", [2,], initializer=tf.truncated_normal_initializer(stddev=0.1))
print v3




#变量矩阵
v4 =  tf.get_variable("aa4", [2,5], initializer=tf.truncated_normal_initializer(stddev=0.1))
print v4




#占位符,运行时候确定维度。所以可用None, 注意常量和变量不可以。
y = tf.placeholder(tf.float32, [None, 5], name='y-input')
print y
Tensor("y-input:0", shape=(?, 5), dtype=float32)


阅读(1311) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~