@@ -492,7 +492,29 @@ def _incr_mean_variance_axis0(
492
492
493
493
494
494
def inplace_csr_row_normalize_l1 (X ):
495
- """ Inplace row normalize using the l1 norm"""
495
+ """ Normalize inplace the rows of a CSR matrix or array by their L1 norm.
496
+
497
+ Parameters
498
+ ----------
499
+ X : scipy.sparse.csr_matrix and scipy.sparse.csr_array, \
500
+ shape=(n_samples, n_features)
501
+ The input matrix or array to be modified inplace.
502
+
503
+ Examples
504
+ --------
505
+ >>> from scipy.sparse import csr_matrix
506
+ >>> from sklearn.utils.sparsefuncs_fast import inplace_csr_row_normalize_l1
507
+ >>> X = csr_matrix(([1.0, 2.0, 3.0], [0, 2, 3], [0, 3, 4]), shape=(3, 4))
508
+ >>> X.toarray()
509
+ array([[1., 2., 0., 0.],
510
+ [0., 0., 3., 0.],
511
+ [0., 0., 0., 4.]])
512
+ >>> inplace_csr_row_normalize_l1(X)
513
+ >>> X.toarray()
514
+ array([[0.33... , 0.66... , 0. , 0. ],
515
+ [0. , 0. , 1. , 0. ],
516
+ [0. , 0. , 0. , 1. ]])
517
+ """
496
518
_inplace_csr_row_normalize_l1(X.data, X.shape, X.indices, X.indptr)
497
519
498
520
@@ -529,7 +551,28 @@ def _inplace_csr_row_normalize_l1(
529
551
530
552
531
553
def inplace_csr_row_normalize_l2 (X ):
532
- """ Inplace row normalize using the l2 norm"""
554
+ """ Normalize inplace the rows of a CSR matrix or array by their L2 norm.
555
+
556
+ Parameters
557
+ ----------
558
+ X : scipy.sparse.csr_matrix, shape=(n_samples, n_features)
559
+ The input matrix or array to be modified inplace.
560
+
561
+ Examples
562
+ --------
563
+ >>> from scipy.sparse import csr_matrix
564
+ >>> from sklearn.utils.sparsefuncs_fast import inplace_csr_row_normalize_l2
565
+ >>> X = csr_matrix(([1.0, 2.0, 3.0], [0, 2, 3], [0, 3, 4]), shape=(3, 4))
566
+ >>> X.toarray()
567
+ array([[1., 2., 0., 0.],
568
+ [0., 0., 3., 0.],
569
+ [0., 0., 0., 4.]])
570
+ >>> inplace_csr_row_normalize_l2(X)
571
+ >>> X.toarray()
572
+ array([[0.44... , 0.89... , 0. , 0. ],
573
+ [0. , 0. , 1. , 0. ],
574
+ [0. , 0. , 0. , 1. ]])
575
+ """
533
576
_inplace_csr_row_normalize_l2(X.data, X.shape, X.indices, X.indptr)
534
577
535
578
0 commit comments