tf.keras.backend.is_sparse

TensorFlow 1 version View source on GitHub

Returns whether a tensor is a sparse tensor.

tf.keras.backend.is_sparse(tensor)

Arguments:

  • tensor: A tensor instance.

Returns:

A boolean.

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; a = K.placeholder((2, 2), sparse=False)</code>
<code class="no-select nocode">    &gt;&gt;&gt; print(K.is_sparse(a))</code>
<code class="no-select nocode">    False</code>
<code class="no-select nocode">    &gt;&gt;&gt; b = K.placeholder((2, 2), sparse=True)</code>
<code class="no-select nocode">    &gt;&gt;&gt; print(K.is_sparse(b))</code>
<code class="no-select nocode">    True</code>
</pre>

Compat aliases