tf.keras.backend.is_sparse

TensorFlow 1 version View source on GitHub

Returns whether a tensor is a sparse tensor.

tensor A tensor instance.

A boolean.

Example:

a = tf.keras.backend.placeholder((2, 2), sparse=False)
print(tf.keras.backend.is_sparse(a))
False
b = tf.keras.backend.placeholder((2, 2), sparse=True)
print(tf.keras.backend.is_sparse(b))
True