tf.keras.backend.ndim

TensorFlow 1 version View source on GitHub

Returns the number of axes in a tensor, as an integer.

tf.keras.backend.ndim(x)

Arguments:

  • x: Tensor or variable.

Returns:

Integer (scalar), number of axes.

Examples:

<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; input = K.placeholder(shape=(2, 4, 5))</code>
<code class="no-select nocode">    &gt;&gt;&gt; val = np.array([[1, 2], [3, 4]])</code>
<code class="no-select nocode">    &gt;&gt;&gt; kvar = K.variable(value=val)</code>
<code class="no-select nocode">    &gt;&gt;&gt; K.ndim(input)</code>
<code class="no-select nocode">    3</code>
<code class="no-select nocode">    &gt;&gt;&gt; K.ndim(kvar)</code>
<code class="no-select nocode">    2</code>
</pre>

Compat aliases