2017年7月20日星期四

tf.reshape() 详解

身边有个大神好处就在不懂可以问,心情愉悦的时候可以听个训。
遇到一个问题,在代码的计算过程中,会产生一个中间结果:
[[ 0.00092188],
 [ 0.00088835],
 [ 0.00133359],
 [ 0.00087597],
 [ 0.00090471],
 [ 0.00152732],
 [ 0.00098235],
 [ 0.0012522 ],
 [ 0.00301147],
 [ 0.00139072],
 [ 0.00146918]]

我要将它变成[0.00092188, 0.00088835,...]的数据格式。网上没看到解释,问了下大神,大神说用tf.reshape()就可以了,笔者之前以为tf.reshape()只能把低维变高维,故而查了下tf.reshape()的用法,探索参考[1]:由于很简单,笔者不祥述

为简单起见,笔者实现下述需求:
p = [[1],[2],[3],[4]]
p = tf.Variable(p)
init_op = tf.global_variables_initializer()
q = tf.reshape(p,[-1])
with tf.Session() as sess:
    sess.run(init_op)
    print sess.run(q)

[1]https://www.tensorflow.org/api_docs/python/tf/reshape

没有评论:

发表评论

leetcode 17

17.   Letter Combinations of a Phone Number Medium Given a string containing digits from   2-9   inclusive, return all possible l...