Skip to content

linalg.norm with ord=numpy.inf does not work for empty array #3763

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
felixlen opened this issue Sep 19, 2013 · 3 comments
Closed

linalg.norm with ord=numpy.inf does not work for empty array #3763

felixlen opened this issue Sep 19, 2013 · 3 comments

Comments

@felixlen
Copy link

It may sound silly but it may be of interest to be able to compute the norm of [] so that one has not to catch this case before (would make my code more readable).

At the moment numpy.linalg.norm(numpy.array([]),ord=):

  • works with ord = 0,1,2,... giving the result 0. Although here is a incosistency returning np.int in the case of ord = 0 and np.float in the others.
  • works not not with ord = numpy.inf since this computes abs(x).max() without checking if x is nonempty.

It would be very nice, if in the [] case also for ord = inf one would return 0, which would be consistent with matlab behaviour.

@charris
Copy link
Member

charris commented Feb 23, 2014

This is a bug.

@larsmans
Copy link
Contributor

It's easily fixed by adding a special case

if x.size == 0:
    return 0.

but what about the -inf norm?

@mattip
Copy link
Member

mattip commented Mar 12, 2025

Fixed in #28343

@mattip mattip closed this as completed Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants