Frobenius Norm defined for vectors?
See original GitHub issueThis might be less of an implementation question, and more of a “philosophy” question, but shouldn’t the Frobenius Norm work on Vectors? Source: Wolfram
Currently, the Frobenius Norm in numpy does not accept vectors:
import numpy as np
a = np.random.rand(10, 1)
b = np.squeeze(a)
print(np.linalg.norm(a, 'fro'))
print(np.linalg.norm(b, 'fro'))
Which results in:
1.7594677278427366
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
//anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py in norm(x, ord, axis, keepdims)
2515 try:
-> 2516 ord + 1
2517 except TypeError:
TypeError: can only concatenate str (not "int") to str
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-18-2ace847024a5> in <module>
3 b = np.squeeze(a)
4 print(np.linalg.norm(a, 'fro'))
----> 5 print(np.linalg.norm(b, 'fro'))
<__array_function__ internals> in norm(*args, **kwargs)
//anaconda3/lib/python3.7/site-packages/numpy/linalg/linalg.py in norm(x, ord, axis, keepdims)
2516 ord + 1
2517 except TypeError:
-> 2518 raise ValueError("Invalid norm order for vectors.")
2519 absx = abs(x)
2520 absx **= ord
ValueError: Invalid norm order for vectors.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
ALAFF The Frobenius norm - UT Computer Science
One can think of the Frobenius norm as taking the columns of the matrix, stacking them on top of each other to create...
Read more >What is the significance of the Frobenius norm? - Quora
The Frobenius norm is a measure of the magnitude of a matrix. · It is defined as the sum of the squares of...
Read more >Frobenius Norm - an overview | ScienceDirect Topics
The Frobenius norm requires that we cycle through all matrix entries, add their squares, and then take the square root. This involves an...
Read more >What is the difference between the Frobenius norm and the 2 ...
The Frobenius norm is always at least as large as the spectral radius. The Frobenius norm is at most √r ...
Read more >Finding the Frobenius Norm of a given matrix - GeeksforGeeks
Given an M * N matrix, the task is to find the Frobenius Norm of the matrix. The Frobenius Norm of a matrix...
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 Free
Top 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
The problem is actually a bit further down in the code - if you follow the traceback from the error you received originally, you should be able to find the offending bit.
As mentioned in the discussions in #14719 and #14215, the behavior for >2 dimensions is a separate issue - it would be best if you could limit this PR to the bug in kwarg handling.
Re: resources for testing/contributing: take a look at NumPy’s contribution guidelines. You can also take a look at linalg tests in
numpy/linalg/tests/test_linalg.py
to get an idea of how tests are formulated and where additional tests might be appropriate. Hope that helps!Since this is my first issue, Are there any resources for making proper tests and a pull request?
(Also, if I was to clone the numpy repo and run setup.py, how would I make sure which numpy version I use when I import numpy?)
I would argue if ord is ‘fro’, then lines 2512-14 below.
https://github.com/numpy/numpy/blob/dae4f67c797176c66281101be8f3b4d6c424735c/numpy/linalg/linalg.py#L2510-L2524
Would need to be changed to:
Assuming everyone agrees that an nth order array has a Forbenious Norm that is naturally summing up squares of each element.