tf.contrib.distributions.fill_triangular
Stay organized with collections
Save and categorize content based on your preferences.
Creates a (batch of) triangular matrix from a vector of inputs.
tf.contrib.distributions.fill_triangular(
x, upper=False, name=None
)
Created matrix can be lower- or upper-triangular. (It is more efficient to
create the matrix as upper or lower, rather than transpose.)
Triangular matrix elements are filled in a clockwise spiral. See example,
below.
If x.get_shape()
is [b1, b2, ..., bB, d]
then the output shape is
[b1, b2, ..., bB, n, n]
where n
is such that d = n(n+1)/2
, i.e.,
n = int(np.sqrt(0.25 + 2. * m) - 0.5)
.
Example:
fill_triangular([1, 2, 3, 4, 5, 6])
# ==> [[4, 0, 0],
# [6, 5, 0],
# [3, 2, 1]]
fill_triangular([1, 2, 3, 4, 5, 6], upper=True)
# ==> [[1, 2, 3],
# [0, 5, 6],
# [0, 0, 4]]
For comparison, a pure numpy version of this function can be found in
util_test.py
, function _fill_triangular
.
Args |
x
|
Tensor representing lower (or upper) triangular elements.
|
upper
|
Python bool representing whether output matrix should be upper
triangular (True ) or lower triangular (False , default).
|
name
|
Python str . The name to give this op.
|
Returns |
tril
|
Tensor with lower (or upper) triangular elements filled from x .
|
Raises |
ValueError
|
if x cannot be mapped to a triangular matrix.
|
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.
Last updated 2020-10-01 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 2020-10-01 UTC."],[],[],null,["# tf.contrib.distributions.fill_triangular\n\n\u003cbr /\u003e\n\n|--------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/ops/distributions/util.py#L797-L909) |\n\nCreates a (batch of) triangular matrix from a vector of inputs. \n\n tf.contrib.distributions.fill_triangular(\n x, upper=False, name=None\n )\n\nCreated matrix can be lower- or upper-triangular. (It is more efficient to\ncreate the matrix as upper or lower, rather than transpose.)\n\nTriangular matrix elements are filled in a clockwise spiral. See example,\nbelow.\n\nIf `x.get_shape()` is `[b1, b2, ..., bB, d]` then the output shape is\n`[b1, b2, ..., bB, n, n]` where `n` is such that `d = n(n+1)/2`, i.e.,\n`n = int(np.sqrt(0.25 + 2. * m) - 0.5)`.\n\n#### Example:\n\n fill_triangular([1, 2, 3, 4, 5, 6])\n # ==\u003e [[4, 0, 0],\n # [6, 5, 0],\n # [3, 2, 1]]\n\n fill_triangular([1, 2, 3, 4, 5, 6], upper=True)\n # ==\u003e [[1, 2, 3],\n # [0, 5, 6],\n # [0, 0, 4]]\n\nFor comparison, a pure numpy version of this function can be found in\n`util_test.py`, function `_fill_triangular`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|------------------------------------------------------------------------------------------------------------------------------|\n| `x` | `Tensor` representing lower (or upper) triangular elements. |\n| `upper` | Python `bool` representing whether output matrix should be upper triangular (`True`) or lower triangular (`False`, default). |\n| `name` | Python `str`. The name to give this op. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|--------|---------------------------------------------------------------------|\n| `tril` | `Tensor` with lower (or upper) triangular elements filled from `x`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-------------------------------------------------|\n| `ValueError` | if `x` cannot be mapped to a triangular matrix. |\n\n\u003cbr /\u003e"]]