sklearn.utils.extmath
.safe_sparse_dot¶
-
sklearn.utils.extmath.
safe_sparse_dot
(a, b, dense_output=False)[source]¶ Dot product that handle the sparse matrix case correctly
Uses BLAS GEMM as replacement for numpy.dot where possible to avoid unnecessary copies.
- Parameters
- aarray or sparse matrix
- barray or sparse matrix
- dense_outputboolean, default False
When False, either
a
orb
being sparse will yield sparse output. When True, output will always be an array.
- Returns
- dot_productarray or sparse matrix
sparse if
a
orb
is sparse anddense_output=False
.