`linalg.hankel` returns unexpected results
See original GitHub issueA Hankel matrix is supposed to be a square matrix, but the scipy
implementation can sometimes return non-square matrices, which I think is misleading/unexpected:
In [1]: from scipy import linalg
In [2]: linalg.hankel([1, 2, 3], [4, 5, 6, 7, 8, 9])
Out[2]:
array([[1, 2, 3, 5, 6, 7],
[2, 3, 5, 6, 7, 8],
[3, 5, 6, 7, 8, 9]])
Note that 4
is not included in the output, which may be unexpected (I know that the documentation says that r[0]
is ignored, but the initial description of r
is “the last row” of the matrix, so at the very least the documentation could do a better job clarifying). This output seems much more reasonable as it captures all elements from both arrays and returns a square matrix:
array([[1, 2, 3, 4, 5],
[2, 3, 4, 5, 6],
[3, 4, 5, 6, 7],
[4, 5, 6, 7, 8],
[5, 6, 7, 8, 9]])
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
scipy.linalg.hankel — SciPy v1.9.3 Manual
Construct a Hankel matrix. The Hankel matrix has constant anti-diagonals, with c as its first column and r as its last row. If...
Read more >scipy/linalg.py at main - GitHub
scipy/benchmarks/benchmarks/linalg.py ... return rand(*size) ... Retain old benchmark results (remove this if changing the benchmark).
Read more >arXiv:2002.06621v3 [math.NA] 4 Sep 2020
Experimental results show that the proposed algorithm usually achieves good accuracy and shows a higher robustness with respect to the initial ...
Read more >Unexpected result using linalg.matrix_rank in numpy.linalg ...
This was based on the definition of rank as being the number of rows of the largest determinant so formed from the matrix....
Read more >Foundations of System Theory: The Hankel Matrix* - CORE
for nonlinear state-space description, we define the Hankel matrix for an arbitrary adjoint system. This returns the usual definition for linear systems,.
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
There are a couple of things to unpack here. First is that when given two arguments hence working in the context of nonsymmetric Hankel matrix the result is exactly like as required. It has to be a rectangle matrix otherwise the result is not a Hankel matrix.
The data problem here is that the user supplied arrays are not compatible for forming a Hankel matrix, that is to say, the last element of the
c
must match the first element ofr
. Because that is the property of being a Hankel matrix; constant anti-diagonals.Matlab handles the violation with a warning in scipy historically it is chosen to ignore the first element since it is supposed to be the last element of the column anyways otherwise Hankelness is not preserved.
The point can be emphasized better and I’d appreciate a PR for that but this property of the Hankel matrix can be expected also from the user since the result should be familiar.
No problem at all. The difference is the way the function is called. Suppose you are trying to form the array you got from the current implementation
what should be the input in your proposed syntax?