Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: Fix problems with linalg.norm with ord=numpy.inf #10688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion numpy/linalg/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,10 @@ def norm(x, ord=None, axis=None, keepdims=False):
raise TypeError("'axis' must be None, an integer or a tuple of integers")
axis = (axis,)

#Deals with the edge case where if the ord is infinite and empty then the function does not output 0 as it should for any empty array.
if x.size == 0:
return 0

if len(axis) == 1:
if ord == Inf:
return abs(x).max(axis=axis, keepdims=keepdims)
Expand Down Expand Up @@ -2367,7 +2371,7 @@ def norm(x, ord=None, axis=None, keepdims=False):
return ret
else:
raise ValueError("Improper number of dimensions to norm.")


# multi_dot

Expand Down
1 change: 1 addition & 0 deletions numpy/linalg/tests/test_linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,7 @@ 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)
assert_equal(norm(array([]),inf))

def test_vector_return_type(self):
a = np.array([1, 0, 1])
Expand Down