MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / reshape

Function reshape

tensorflow/python/ops/array_ops.py:60–133  ·  view source on GitHub ↗

r"""Reshapes a tensor. Given `tensor`, this operation returns a tensor that has the same values as `tensor` with shape `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` o

(tensor, shape, name=None)

Source from the content-addressed store, hash-verified

58
59@tf_export("reshape", v1=["reshape", "manip.reshape"])
60def reshape(tensor, shape, name=None): # pylint: disable=redefined-outer-name
61 r"""Reshapes a tensor.
62
63 Given `tensor`, this operation returns a tensor that has the same values
64 as `tensor` with shape `shape`.
65
66 If one component of `shape` is the special value -1, the size of that
67 dimension is computed so that the total size remains constant. In particular,
68 a `shape` of `[-1]` flattens into 1-D. At most one component of `shape` can
69 be -1.
70
71 If `shape` is 1-D or higher, then the operation returns a tensor with shape
72 `shape` filled with the values of `tensor`. In this case, the number of
73 elements implied by `shape` must be the same as the number of elements in
74 `tensor`.
75
76 For example:
77
78 ```
79 # tensor 't' is [1, 2, 3, 4, 5, 6, 7, 8, 9]
80 # tensor 't' has shape [9]
81 reshape(t, [3, 3]) ==> [[1, 2, 3],
82 [4, 5, 6],
83 [7, 8, 9]]
84
85 # tensor 't' is [[[1, 1], [2, 2]],
86 # [[3, 3], [4, 4]]]
87 # tensor 't' has shape [2, 2, 2]
88 reshape(t, [2, 4]) ==> [[1, 1, 2, 2],
89 [3, 3, 4, 4]]
90
91 # tensor 't' is [[[1, 1, 1],
92 # [2, 2, 2]],
93 # [[3, 3, 3],
94 # [4, 4, 4]],
95 # [[5, 5, 5],
96 # [6, 6, 6]]]
97 # tensor 't' has shape [3, 2, 3]
98 # pass '[-1]' to flatten 't'
99 reshape(t, [-1]) ==> [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6]
100
101 # -1 can also be used to infer the shape
102
103 # -1 is inferred to be 9:
104 reshape(t, [2, -1]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],
105 [4, 4, 4, 5, 5, 5, 6, 6, 6]]
106 # -1 is inferred to be 2:
107 reshape(t, [-1, 9]) ==> [[1, 1, 1, 2, 2, 2, 3, 3, 3],
108 [4, 4, 4, 5, 5, 5, 6, 6, 6]]
109 # -1 is inferred to be 3:
110 reshape(t, [ 2, -1, 3]) ==> [[[1, 1, 1],
111 [2, 2, 2],
112 [3, 3, 3]],
113 [[4, 4, 4],
114 [5, 5, 5],
115 [6, 6, 6]]]
116
117 # tensor 't' is [7]

Callers 12

boolean_maskFunction · 0.70
zerosFunction · 0.70
onesFunction · 0.70
meshgridFunction · 0.70
_batch_gatherFunction · 0.70
batch_gather_ndFunction · 0.70
searchsortedFunction · 0.70
repeat_with_axisFunction · 0.70
_with_nonzero_rankFunction · 0.70
repeatFunction · 0.70

Calls 1

reshapeMethod · 0.80