Compute density of a sparse vector.
The input data can be numpy ndarray or a sparse matrix.
The density of w, between 0 and 1.
>>> from scipy import sparse >>> from sklearn.utils.extmath import density >>> X = sparse.random(10, 10, density=0.25, random_state=0) >>> density(X) 0.25
© 2007–2025 The scikit-learn developers
Licensed under the 3-clause BSD License.
https://scikit-learn.org/1.6/modules/generated/sklearn.utils.extmath.density.html