tf.reshape(tensor, shape, name=None)###
Reshapes a tensor.
重塑一个张量
Given tensor, this operation returns a tensor that has the same values as tensor with shape shape.
给定一个tensor,这个操作会返回一个有着跟原tensor一样的值且经过shape重塑过的张量。
If one component of shape is the special value -1, the size of that dimension is computed so that the total size remains constant. In particular, a shape of [-1] flattens into 1-D. At most one component of shape can be -1.
如果shape中存在值为-1的组成,被计算过的维度总和的大小将保持恒定。尤其是当一个为[-1]的shape被展平为一维,且shape最多只能存在一个-1。
If shape is 1-D or higher, then the operation returns a tensor with shape shape filled with the values of tensor. In this case, the number of elements implied by shape must be the same as the number of elements in tensor.
如果shape是一维或者是更高维度,那么这个操作将会返回一个形状为shape,填充满value值的张量。在这种情况下,shape的元素的数量必须与tensor的元素数量一样。
For example:
# 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 scalarreshape(t, []) ==> 7`
Args:
tensor: A Tensor.
shape: A Tensor. Must be one of the following types: int32, int64. Defines the shape of the output tensor.
name: A name for the operation (optional).
参数:
tensor: 一个张量。
shape: 一个张量。必须为下列类型之一:int32, int64. 决定输出张量的形状。
name: 操作的名字 (可选参数).
Returns:
A Tensor. Has the same type as tensor.
返回值:
一个张量。有着跟tensor一致的类型。