tf.raw_ops.Reshape
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
Reshapes a tensor.
View aliases
Compat aliases for migration
See
Migration guide for
more details.
tf.compat.v1.raw_ops.Reshape
tf.raw_ops.Reshape(
tensor, shape, name=None
)
Given tensor
, this operation returns a tensor that has the same values
as tensor
with shape shape
.
If one component of 1-D tensor 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
may be
unknown.
The shape
must be 1-D and 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
.
It is an error if shape
is not 1-D.
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 scalar
reshape(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).
|
Returns |
A Tensor . Has the same type as tensor .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.raw_ops.Reshape\n\n\u003cbr /\u003e\n\nReshapes a tensor.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.raw_ops.Reshape`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/Reshape)\n\n\u003cbr /\u003e\n\n tf.raw_ops.Reshape(\n tensor, shape, name=None\n )\n\nGiven `tensor`, this operation returns a tensor that has the same values\nas `tensor` with shape `shape`.\n\nIf one component of 1-D tensor `shape` is the special value -1, the size of that\ndimension is computed so that the total size remains constant. In particular, a\n`shape` of `[-1]` flattens into 1-D. At most one component of `shape` may be\nunknown.\n\nThe `shape` must be 1-D and the operation returns a tensor with shape\n`shape` filled with the values of `tensor`. In this case, the number of elements\nimplied by `shape` must be the same as the number of elements in `tensor`.\n\nIt is an error if `shape` is not 1-D.\n\n#### For example:\n\n # tensor 't' is [1, 2, 3, 4, 5, 6, 7, 8, 9]\n # tensor 't' has shape [9]\n reshape(t, [3, 3]) ==\u003e [[1, 2, 3],\n [4, 5, 6],\n [7, 8, 9]]\n\n # tensor 't' is [[[1, 1], [2, 2]],\n # [[3, 3], [4, 4]]]\n # tensor 't' has shape [2, 2, 2]\n reshape(t, [2, 4]) ==\u003e [[1, 1, 2, 2],\n [3, 3, 4, 4]]\n\n # tensor 't' is [[[1, 1, 1],\n # [2, 2, 2]],\n # [[3, 3, 3],\n # [4, 4, 4]],\n # [[5, 5, 5],\n # [6, 6, 6]]]\n # tensor 't' has shape [3, 2, 3]\n # pass '[-1]' to flatten 't'\n reshape(t, [-1]) ==\u003e [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]\n\n # -1 can also be used to infer the shape\n\n # -1 is inferred to be 9:\n reshape(t, [2, -1]) ==\u003e [[1, 1, 1, 2, 2, 2, 3, 3, 3],\n [4, 4, 4, 5, 5, 5, 6, 6, 6]]\n # -1 is inferred to be 2:\n reshape(t, [-1, 9]) ==\u003e [[1, 1, 1, 2, 2, 2, 3, 3, 3],\n [4, 4, 4, 5, 5, 5, 6, 6, 6]]\n # -1 is inferred to be 3:\n reshape(t, [ 2, -1, 3]) ==\u003e [[[1, 1, 1],\n [2, 2, 2],\n [3, 3, 3]],\n [[4, 4, 4],\n [5, 5, 5],\n [6, 6, 6]]]\n\n # tensor 't' is [7]\n # shape `[]` reshapes to a scalar\n reshape(t, []) ==\u003e 7\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------|-----------------------------------------------------------------------------------------------------------|\n| `tensor` | A `Tensor`. |\n| `shape` | A `Tensor`. Must be one of the following types: `int32`, `int64`. Defines the shape of the output tensor. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor`. Has the same type as `tensor`. ||\n\n\u003cbr /\u003e"]]