question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implementation of matrix norm for order greater than 2

See original GitHub issue

When using numpy.linalg.norm with ord different from 2, for example 3, then I expected the norm to be computed according to the documentation, i.e. as sum(abs(x)**ord)**(1./ord)

But instead I got:

ValueError                                Traceback (most recent call last)
<ipython-input-784-3344f4d8d663> in <module>()
----> 1 nnorm((distpdfs_diverg['BC']/n_samples) - np.eye(n_bundles), 3)

/usr/lib/python3.5/site-packages/numpy/linalg/linalg.py in norm(x, ord, axis, keepdims)
   2247             ret = _multi_svd_norm(x, row_axis, col_axis, sum)
   2248         else:
-> 2249             raise ValueError("Invalid norm order for matrices.")
   2250         if keepdims:
   2251             ret_shape = list(x.shape)

ValueError: Invalid norm order for matrices.

Looking at the source code (numpy 1.13, numpy 1.14, and current) it seems it is simply the norm is simply not implemented for ord greater than 2 contrarily to what the doc says. Would that be something difficult to do?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
pvcommented, Mar 8, 2018

Yes, ord=(p, q) could also be possible. The implementation is in principle one-liner.

1reaction
eric-wiesercommented, Mar 8, 2018

This is as documented:

=====  ============================  ==========================
ord    norm for matrices             norm for vectors
=====  ============================  ==========================
other  --                            sum(abs(x)**ord)**(1./ord)
=====  ============================  ==========================

Note the column for matrices is blank

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chapter 4: Matrix Norms
Since the 2-norm used in the majority of applications, we will adopt it as our default. In what follows, an "un-designated" norm A...
Read more >
NumPy Norm: Understanding np.linalg.norm()
A norm is a measure of the size of a matrix or vector and you can ... ord=2) does not compute the L2...
Read more >
Matrix Norm - an overview | ScienceDirect Topics
Matrix Norm. Matrix norms can be defined based on a set of axioms or properties. From: Digital Control Engineering (Second Edition), 2013 ...
Read more >
Chapter 4 Vector Norms and Matrix Norms - UPenn CIS
In order to define how close two vectors or two matrices are, and in order to ... Example 4.1. ... More generally, we...
Read more >
Matrix norm - Wikipedia
In mathematics, a matrix norm is a vector norm in a vector space whose elements (vectors) are matrices (of given dimensions).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found