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

Function expand_dims

tensorflow/python/ops/ragged/ragged_array_ops.py:384–464  ·  view source on GitHub ↗

Inserts a dimension with shape 1 into a potentially ragged tensor's shape. Given a potentially ragged tenor `input`, this operation inserts a dimension with size 1 at the dimension `axis` of `input`'s shape. * If `input` is a `Tensor`, then this is equivalent to `tf.expand_dims`. * If

(input, axis, name=None)

Source from the content-addressed store, hash-verified

382
383
384def expand_dims(input, axis, name=None): # pylint: disable=redefined-builtin
385 """Inserts a dimension with shape 1 into a potentially ragged tensor's shape.
386
387 Given a potentially ragged tenor `input`, this operation inserts a
388 dimension with size 1 at the dimension `axis` of `input`'s shape.
389
390 * If `input` is a `Tensor`, then this is equivalent to
391 `tf.expand_dims`.
392 * If `input` is ragged, and `axis=0`, then the new dimension will be
393 uniform; but the previously outermost dimension will become ragged.
394 * If `input` is ragged, and `0 < axis < input.ragged_rank`, then the
395 new dimension will be ragged.
396 * If `input` is ragged, and axis >= input.ragged_rank`, then the new
397 dimension will be uniform.
398
399 The following table gives some examples showing how `ragged.expand_dims`
400 impacts the shapes of different input tensors. Ragged dimensions are
401 indicated by enclosing them in parentheses.
402
403 input.shape | axis | result.shape
404 ----------------------- | ---- | -----------------------------
405 `[D1, D2]` | `0` | `[1, D1, D2]`
406 `[D1, D2]` | `1` | `[D1, 1, D2]`
407 `[D1, D2]` | `2` | `[D1, D2, 1]`
408 `[D1, (D2), (D3), D4]` | `0` | `[1, (D1), (D2), (D3), D4]`
409 `[D1, (D2), (D3), D4]` | `1` | `[D1, (1), (D2), (D3), D4]`
410 `[D1, (D2), (D3), D4]` | `2` | `[D1, (D2), (1), (D3), D4]`
411 `[D1, (D2), (D3), D4]` | `3` | `[D1, (D2), (D3), 1, D4]`
412 `[D1, (D2), (D3), D4]` | `4` | `[D1, (D2), (D3), D4, 1]`
413
414 Args:
415 input: The potentially tensor that should be expanded with a new
416 dimension.
417 axis: An integer constant indicating where the new dimension should be
418 inserted.
419 name: A name for the operation (optional).
420
421 Returns:
422 A tensor with the same values as `input`, with an added dimension of
423 size 1 at `axis`.
424
425 #### Examples:
426 ```python
427 >>> rt = tf.ragged.constant([[1, 2], [3]])
428 >>> print rt.shape
429 TensorShape([2, None])
430
431 >>> expanded = ragged.expand_dims(rt, axis=0)
432 >>> print(expanded.shape, expanded)
433 TensorShape([1, None, None]) [[[1, 2], [3]]]
434
435 >>> expanded = ragged.expand_dims(rt, axis=1)
436 >>> print(expanded.shape, expanded)
437 TensorShape([2, None, None]) [[[1, 2]], [[3]]]
438
439 >>> expanded = ragged.expand_dims(rt, axis=2)
440 >>> print(expanded.shape, expanded)
441 TensorShape([2, None, 1]) [[[1], [2]], [[3]]]

Callers

nothing calls this directly

Calls 7

is_raggedMethod · 0.80
nrowsMethod · 0.80
from_row_splitsMethod · 0.80
name_scopeMethod · 0.45
expand_dimsMethod · 0.45
stackMethod · 0.45
rangeMethod · 0.45

Tested by

no test coverage detected