tf.keras.backend.eye

TensorFlow 1 version View source on GitHub

Instantiate an identity matrix and returns it.

tf.keras.backend.eye(
    size,
    dtype=None,
    name=None
)

Arguments:

  • size: Integer, number of rows/columns.
  • dtype: String, data type of returned Keras variable.
  • name: String, name of returned Keras variable.

Returns:

A Keras variable, an identity matrix.

Example:

<pre class="devsite-click-to-copy prettyprint lang-py">
<code class="devsite-terminal" data-terminal-prefix="&gt;&gt;&gt;">from keras import backend as K</code>
<code class="no-select nocode">    &gt;&gt;&gt; kvar = K.eye(3)</code>
<code class="no-select nocode">    &gt;&gt;&gt; K.eval(kvar)</code>
<code class="no-select nocode">    array([[ 1.,  0.,  0.],</code>
<code class="no-select nocode">           [ 0.,  1.,  0.],</code>
<code class="no-select nocode">           [ 0.,  0.,  1.]], dtype=float32)</code>
</pre>

Compat aliases