TensorFlow的reshape操作 tf.reshape
2017-07-31 14:45
375 查看
转自:http://blog.csdn.net/lxg0807/article/details/53021859 如有侵权,请联系博主删除。
函数:tf.reshape(tensor, shape, name=None)
作用:将tensor变换为参数shape的形式。
参数:其中shape为一个列表形式,特殊的一点是列表中可以存在-1。-1代表的含义是不用我们自己指定这一维的大小,函数会自动计算,但列表中只能存在一个-1。(当然如果存在多个-1,就是一个存在多解的方程了)
好了我想说的重点还有一个就是根据shape如何变换矩阵。其实简单的想就是,
reshape(t, shape) => reshape(t, [-1]) => reshape(t, shape)
首先将矩阵t变为一维矩阵,然后再对矩阵的形式更改就可以了。
官方的例子:
函数:tf.reshape(tensor, shape, name=None)
作用:将tensor变换为参数shape的形式。
参数:其中shape为一个列表形式,特殊的一点是列表中可以存在-1。-1代表的含义是不用我们自己指定这一维的大小,函数会自动计算,但列表中只能存在一个-1。(当然如果存在多个-1,就是一个存在多解的方程了)
好了我想说的重点还有一个就是根据shape如何变换矩阵。其实简单的想就是,
reshape(t, shape) => reshape(t, [-1]) => reshape(t, shape)
首先将矩阵t变为一维矩阵,然后再对矩阵的形式更改就可以了。
官方的例子:
# tensor 't' is [1, 2, 3, 4, 5, 6, 7, 8, 9] # tensor 't' has shape [9] reshape(t, [3, 3]) ==> [[1, 2, 3], [4, 5, 6], [7, 8, 9]] # tensor 't' is [[[1, 1], [2, 2]], # [[3, 3], [4, 4]]] # tensor 't' has shape [2, 2, 2] reshape(t, [2, 4]) ==> [[1, 1, 2, 2], [3, 3, 4, 4]] # tensor 't' is [[[1, 1, 1], # [2, 2, 2]], # [[3, 3, 3], # [4, 4, 4]], # [[5, 5, 5], # [6, 6, 6]]] # tensor 't' has shape [3, 2, 3] # pass '[-1]' to flatten 't' reshape(t, [-1]) ==> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6] # -1 can also be used to infer the shape # -1 is inferred to be 9: reshape(t, [2, -1]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3], [4, 4, 4, 5, 5, 5, 6, 6, 6]] # -1 is inferred to be 2: reshape(t, [-1, 9]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3], [4, 4, 4, 5, 5, 5, 6, 6, 6]] # -1 is inferred to be 3: reshape(t, [ 2, -1, 3]) ==> [[[1, 1, 1], [2, 2, 2], [3, 3, 3]], [[4, 4, 4], [5, 5, 5], [6, 6, 6]]] # tensor 't' is [7] # shape `[]` reshapes to a scalar reshape(t, []) ==> 7
相关文章推荐
- Tensorflow 中的tf.reshape()理解和操作
- TensorFlow的reshape操作 tf.reshape
- TensorFlow的reshape操作 tf.reshape
- TensorFlow的reshape操作 tf.reshape
- tensorflow的reshape操作tf.reshape()
- TensorFlow的reshape操作 tf.reshape
- TensorFlow的reshape操作 tf.reshape
- 【TensorFlow】tf.nn.max_pool实现池化操作
- TensorFlow--tf.nn.max_pool实现池化操作
- 【TensorFlow】tf.nn.max_pool实现池化操作
- TensorFlow如何通过tf.device函数来指定运行每一个操作的设备?
- 【tensorFlow】tf.reshape()报错信息 - TypeError: Expected binary or unicode string, got -1
- 180224 tensorflow之tf.reshape()与tf.concat()应用举例
- TensorFlow 用 tf.nn.max_pool 实现最大池化操作
- 1.Tensorflow 之API函数 tf.reshape
- TensorFlow学习---tf.nn.conv2d实现卷积操作
- 【Tensorflow】tf.reshape 函数
- Tensorflow--tf.reshape
- 第一阶段-入门详细图文讲解tensorflow1.4 API-tf.reshape
- tensorflow 池化操作实例 tf.nn.max_pooling