I am implementing Kalman filter in numpy. It works fine, except when I import matplotlib.pyplot to render the result:
import numpy as np import matplotlib.pyplot as plt
Full code here . Let me emphasize that it works correctly before I import; it prints an array of 100 x 2 numbers that are believable. After adding the import, without even using anything from pyplot, all the lines after the specific nan line. Figures that are not nan are the same as before.
My first thought was that it might be a name conflict, but it is not. You can easily see that the code does not have a name like โpltโ , in addition, it is not consistent with the behavior described below.
The number of nan lines is different when executing a file from Sublime Text instead of the command line or when I add import matplotlib as mpl before importing pyplot. Again, non- nan numbers are the same as in a properly functioning version.
The debugging attempt only confused me. I added print statements to the problematic iteration of the main loop, which at first gave only nan matrices. However, when I added another expression, print yt , printing matrices with nan unexpectedly had not- nan values. In addition, moving the import sys statement before import numpy as np changes the number of nan lines. During experiments on these lines, I noticed that during the execution of the same file, the values โโchanged several times (by a lot, for example, from 77 to 3.32686992e + 297), and with further re-execution, back to the original values, randomly oscillating between these two exits. There is no saved state, file operations consist of only one call to np.loadtxt .
Additional information that may help: I โโhave Python 2.7.6 and Ubuntu 14.04, although the behavior is similar on someone else's machine with Python 2.7.8 and spyder.
What are the possible sources of this behavior? Right now, I think either witchcraft, matching mysterious hardware crashes on our computers, or an evil virus designed to disrupt Python programmers.