Reputation: 113
I've run into this problem (infinite singular values despite finite entries in an array) several times for relatively small arrays with dimensions around 100 by 100. The arrays are large enough that I've struggled to see a pattern. I give a working example below that I found by rounding the values in one of my matrices, though I wish I could engineer a simpler example.
import numpy as np
kmat = np.zeros((81, 81), dtype='complex')
kmat[([30, 32, 36, 36, 38, 38, 57, 57, 59, 59, 63, 65], [68, 14, 62, 74, 8, 20, 61, 73, 7, 19, 67, 13])] = (0.04+0.03j)
kmat[([31, 31, 37, 58, 64, 64],[35, 47, 41, 40, 34, 46])] = (0.16+0.11j)
kmat[([33, 33, 35, 35, 39, 41, 45, 45, 47, 47, 60, 62, 66, 66, 68, 68, 72, 74], [62, 74, 8, 20, 68, 14, 62, 74, 8, 20, 67, 13, 61, 73, 7, 19, 67, 13])] = (0.03+0.02j)
kmat[([34, 40, 40, 46, 61, 61, 67, 73, 73], [41, 35, 47, 41, 34, 46, 40, 34, 46])] = (0.13+0.09j)
kmat[([30, 30, 32, 32, 36, 38, 57, 59, 63, 63, 65, 65], [62, 74, 8, 20, 68, 14, 67, 13, 61, 73, 7, 19])] = -(0.04+0.03j)
kmat[([31, 37, 37, 58, 58, 64], [41, 35, 47, 34, 46, 40])] = -(0.16+0.11j)
kmat[([33, 35, 39, 39, 41, 41, 45, 47, 60, 60, 62, 62, 66, 68, 72, 72, 74, 74], [68, 14, 62, 74, 8, 20, 68, 14, 61, 73, 7, 19, 67, 13, 61, 73, 7, 19])] = -(0.03+0.02j)
kmat[([34, 34, 40, 46, 46, 61, 67, 67, 73], [35, 47, 41, 35, 47, 40, 34, 46, 40])] = -(0.13+0.09j)
print(np.linalg.svd(kmat, full_matrices = 0, compute_uv = 0))
The output is
[ inf 6.71714225e-001 6.71714225e-001 1.63401346e-001
1.63401346e-001 1.63401346e-001 5.06904064e-017 4.89771960e-017
2.03140157e-017 1.72656309e-017 1.40275705e-017 3.53543469e-018
1.83729709e-018 1.12027584e-018 8.52297427e-020 1.81345172e-033
1.27726594e-034 8.75935866e-035 2.02878907e-036 9.30164632e-049
8.54881928e-050 6.95546444e-051 2.49250115e-052 4.92974326e-053
1.18027016e-064 2.83787877e-066 3.61447306e-067 2.40364993e-069
2.01469630e-069 6.85315161e-081 1.15983261e-085 9.21712550e-086
3.87403183e-097 6.63966512e-102 5.67626333e-102 4.16050009e-118
3.27338859e-134 2.33809507e-150 1.55632960e-166 1.82909508e-182
1.14892283e-198 1.51906443e-214 nan nan
nan nan nan nan
nan nan nan nan
nan nan nan 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 nan nan
nan 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000 0.00000000e+000 0.00000000e+000 0.00000000e+000
0.00000000e+000]
The largest singular value is returned as infinity, inf
. There are also 18 nan
returned, as well as well as some nonzero and zero singular values. However, since every element of my array is not infinite, I don't see where this trouble is originating from.
Why is numpy's svd
giving an infinite singular value for an array with finite values and what can I do to avoid this?
In searching for the answer, I've tried a variety of 3 by 3 matrices, such as those with a column or row of zeros, but the singular values appear to be fine.
Upvotes: 1
Views: 318
Reputation: 21
I had the same error on Intel processors. You can fix this by installing the intel-numpy package.
pip install intel-numpy
More information: https://anaconda.org/intel/numpy
Upvotes: 2