Reputation: 11
Does anyone know how to calculate the L_0 norm
of a vector in R. You can't do the usual sum(x^p)^(1/p)
when p=0
so I was unsure if there was an easy way to do this. Thanks!
Upvotes: 1
Views: 601
Reputation: 818
It really depends how you define the L_0 norm. There is not a clear consensus.
From wikipedia: ℓ0 "norm" by David Donoho — whose quotation marks warn that this function is not a proper norm — is the number of non-zero entries of the vector x. Many authors abuse terminology by omitting the quotation marks. Defining 0^0 = 0,
just use sum(x != 0)
Upvotes: 4