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

Function unstack

tensorflow/python/ops/array_ops.py:1279–1323  ·  view source on GitHub ↗

Unpacks the given dimension of a rank-`R` tensor into rank-`(R-1)` tensors. Unpacks `num` tensors from `value` by chipping it along the `axis` dimension. If `num` is not specified (the default), it is inferred from `value`'s shape. If `value.shape[axis]` is not known, `ValueError` is raised.

(value, num=None, axis=0, name="unstack")

Source from the content-addressed store, hash-verified

1277
1278@tf_export("unstack")
1279def unstack(value, num=None, axis=0, name="unstack"):
1280 """Unpacks the given dimension of a rank-`R` tensor into rank-`(R-1)` tensors.
1281
1282 Unpacks `num` tensors from `value` by chipping it along the `axis` dimension.
1283 If `num` is not specified (the default), it is inferred from `value`'s shape.
1284 If `value.shape[axis]` is not known, `ValueError` is raised.
1285
1286 For example, given a tensor of shape `(A, B, C, D)`;
1287
1288 If `axis == 0` then the i'th tensor in `output` is the slice
1289 `value[i, :, :, :]` and each tensor in `output` will have shape `(B, C, D)`.
1290 (Note that the dimension unpacked along is gone, unlike `split`).
1291
1292 If `axis == 1` then the i'th tensor in `output` is the slice
1293 `value[:, i, :, :]` and each tensor in `output` will have shape `(A, C, D)`.
1294 Etc.
1295
1296 This is the opposite of stack.
1297
1298 Args:
1299 value: A rank `R > 0` `Tensor` to be unstacked.
1300 num: An `int`. The length of the dimension `axis`. Automatically inferred if
1301 `None` (the default).
1302 axis: An `int`. The axis to unstack along. Defaults to the first dimension.
1303 Negative values wrap around, so the valid range is `[-R, R)`.
1304 name: A name for the operation (optional).
1305
1306 Returns:
1307 The list of `Tensor` objects unstacked from `value`.
1308
1309 Raises:
1310 ValueError: If `num` is unspecified and cannot be inferred.
1311 ValueError: If `axis` is out of the range [-R, R).
1312 """
1313 if num is None:
1314 value = ops.convert_to_tensor(value)
1315 value_shape = value.get_shape()
1316 if value_shape.ndims is not None:
1317 if axis < -value_shape.ndims or axis >= value_shape.ndims:
1318 raise ValueError("axis = %d not in [%d, %d)" %
1319 (axis, -value_shape.ndims, value_shape.ndims))
1320 num = value_shape.dims[axis].value
1321 if num is None:
1322 raise ValueError("Cannot infer num from shape %s" % value_shape)
1323 return gen_array_ops.unpack(value, num=num, axis=axis, name=name)
1324
1325
1326@tf_export("concat")

Callers 1

batch_gather_ndFunction · 0.85

Calls 2

get_shapeMethod · 0.45
unpackMethod · 0.45

Tested by

no test coverage detected