The norm of a size zero array should be zero.
See original GitHub issueJust as the empty sum is 0 and the empty product is 1, the empty norm should be 0 in my opinion. In numpy, this convention has been implemented and is unit-tested for the default vector and matrix norms:
def test_empty(self):
assert_equal(norm([]), 0.0)
assert_equal(norm(array([], dtype=self.dt)), 0.0)
assert_equal(norm(atleast_2d(array([], dtype=self.dt))), 0.0)
Some of the non-default empty norms raise exceptions. The induced matrix 2-norm raises exceptions for two reasons – first, attempting to compute the singular values of a size-0 matrix raises an exception, and second, even if the the empty array of singular values were to be returned, attempting to compute the max of an empty sequence also raises an exception. The empty induced matrix 1-norm and np.inf-norm each also raise an exception because they try to compute an empty max.
Issue Analytics
- State:
- Created 9 years ago
- Comments:20 (19 by maintainers)
Top Results From Across the Web
Why can't C arrays have 0 length?
Especially for variable length arrays it makes perfect sense to have a size of zero every once and a while. It is also...
Read more >Numpy's linalg.norm() returning 0 on non-zero-vector?
If we're taking the Euclidean norm of an n-dimensional vector, the only case in which the norm can be 0 is when the...
Read more >Zero Length (Using the GNU Compiler Collection (GCC))
Declaring zero-length arrays is allowed in GNU C as an extension. A zero-length array can be useful as the last element of a...
Read more >Vector and matrix norms - MATLAB norm - MathWorks
a = [0 3]; b = [-2 1];. Use norm to calculate the distance between the points. d = norm(b-a).
Read more >numpy.linalg.norm — NumPy v1.24 Manual
This function is able to return one of eight different matrix norms, ... Input array. ... ord{non-zero int, inf, -inf, 'fro', 'nuc'}, optional....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
On Monday, January 5, 2015, argriffing notifications@github.com wrote:
Since the first and obvious use would be in linalg.norm perhaps they could be added, and exposed only through there. If doing so, it might be worth copying the dnrm2 algorthm too instead of calling dot as norm does now.
Closing as duplicate as noted by Eric. (inf norm on empty array raising error since it calls
max([])
). It sounds like there may have been more issues here, but those have been resolved.