calculate_density

paddle.incubate.asp. 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

System Message: ERROR/3 (/usr/local/lib/python3.8/site-packages/paddle/fluid/contrib/sparsity/utils.py:docstring of paddle.fluid.contrib.sparsity.utils.calculate_density, line 11)

Error in “code-block” directive: maximum 1 argument(s) allowed, 7 supplied.

.. code-block:: python
  import paddle
  import numpy as np

  x = np.array([[0, 1, 3, 0],
                [1, 1, 0, 1]])
  paddle.incubate.asp.calculate_density(x) # 0.625