calculate_density¶
- paddle.static.sparsity. calculate_density ( x ) [source]
-
Return the density of the input tensor.
- Parameters
-
x (nparray) – The input tensor.
- Returns
-
The density of
x
. - Return type
-
float
Examples
import numpy as np import paddle.static.sparsity as sparsity x = np.array([[0, 1, 3, 0], [1, 1, 0, 1]]) sparsity.calculate_density(x) # 0.625