The issue described below has been replicated
import numpy as np
import matplotlib.pyplot as plt
x = np.random.randint(5, size=(100, 12), dtype=np.int64)
# [THERE IS ACTUALLY NO NEED TO SET THE DATA TYPE
# `x = np.random.rand(100, 12)` yields the same problem]
and you want to compute x
's rank.
>>> np.linalg.matrix_rank(x)
12
Everything is fine. Let's restart a new session from scratch, whose underlying code this time is
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(1010) # <-----
x = np.random.randint(5, size=(100, 12), dtype=np.int64)
x_vals = y_vals = np.arange(0, .5, .05)
plt.plot(x_vals, y_vals, linestyle='--')
print(np.linalg.matrix_rank(x))
This prints 0
(!!). And more surprisingly, the reason behind this is the value given to linestyle
(!!). I mean, having linestyle='-'
(solid) turns everything back to normal.
This is clearly an undesired behavior (I literally spent hours to locate precisely)... but still:
How ?
numpy==1.19.2 # since 1.19.0 actually
matplotlib==3.3.3 # between 3.1.3 and 3.3.3 for what I can tell
No problem under Linux (with the same environment)
x
's shape. Hard to tell exactly. However, this is not random either, and is monotonously linked to x
's (vertical and/or horizontal) shape.x
is exactly the same when compared to itself before plt.plot
is called (compared using joblib.hash
)This question is more about leaving a trace than getting an answer. This is so weird that I had to write it somewhere. I've changed my linestyle
...
The title of the question is sufficiently unequivocal to drive people with the same problem as mine here.
The GIF's code follows.
import numpy as np
import matplotlib.pyplot as plt
import joblib as jl
linestyles = [
'solid', '-',
'dotted', # '.', => ValueError: '.'
'dashed', '--',
'dashdot', '-.',
':', '', ' '
]
for ls in linestyles:
print(26*'*', f"linestyle='{ls}'")
np.random.seed(1010)
x = np.random.rand(9, 5)
h0 = jl.hash(x)
x_vals = y_vals = np.arange(0, .5, .05)
plt.plot(x_vals, y_vals, linestyle=ls)
# plt.show()
h1 = jl.hash(x)
mr = np.linalg.matrix_rank(x)
print(
'\t', mr, (not mr)*'<---------------[!!!]'
)
print('\t', 'Has not changed:', h0 == h1)
This is a bug in numpy and has been corrected as of version 1.19.3:
There is a known problem with Windows 10 version=2004 and OpenBLAS svd that we are trying to debug. If you are running that Windows version you should use a NumPy version that links to the MKL library, earlier Windows versions are fine.
https://github.com/numpy/numpy/releases/tag/v1.19.2
NumPy 1.19.3 is a small maintenace release with two major improvements:
- Python 3.9 binary wheels on all supported platforms.
- OpenBLAS fixes for Windows 10 version 2004 fmod bug.
https://github.com/numpy/numpy/releases/tag/v1.19.3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With