Jan
Jan

Reputation: 1479

Can numpy.linalg.norm replace sklearn.preprocessing.normalize(X, norm='l1',) for L1-norm of matrix?

I used sklearn.preprocessing.normalize before but I wonder there are other ways by Numpy (or something else) for L1-norm of matrix? Can we use numpy.linalg.norm(x, ord=None, axis=None, keepdims=False)instead of sklearn one?

According to the document, linalg.norm params seem not possible for matrix nor L1

x : array_like Input array. If axis is None, x must be 1-D or 2-D.
ord : {non-zero int, inf, -inf, ‘fro’, ‘nuc’}, optional

Upvotes: 0

Views: 802

Answers (1)

YLJ
YLJ

Reputation: 2996

Yes. numpy.linalg.norm is for Matrix or vector norm.

It depends on which kind of L1 matrix norm you want. You can specify it with argument ord. (Doc)

numpy.linalg.norm(x, ord=None, axis=None, keepdims=False)

Matrix norms induced by vector norms, ord=inf

"Entrywise" matrix norms, ord=0

Schatten norms, ord=nuc

Upvotes: 1

Related Questions