Python/Numpy MemoryError

Rewrite to and this will use much less memory. Whereas p = p*alpha allocates a whole new matrix for the result of p*alpha and then discards the old p; p*= alpha does the same thing in place. In general, with big matrices, try to use op= assignment.

scipy.signal.spectrogram compared to matplotlib.pyplot.specgram

The following code generates a spectrogram using either scipy.signal.spectrogram or matplotlib.pyplot.specgram. The color contrast of the specgram function is, however, rather low. Is there a way to increase it? Using matplotlib.pyplot.specgram gives the following result: Using scipy.signal.spectrogram gives the following plot Both functions seem to use the ‘jet’ colormap. I would also be generally interested in the difference between the two functions. Although they … Read more

Overflow Error in Python’s numpy.exp function

As fuglede says, the issue here is that np.float64 can’t handle a number as large as exp(1234.1). Try using np.float128 instead: Note however, that there are certain quirks with using extended precision. It may not work on Windows; you don’t actually get the full 128 bits of precision; and you might lose the precision whenever the number passes through pure … Read more

Overflow Error in Python’s numpy.exp function

As fuglede says, the issue here is that np.float64 can’t handle a number as large as exp(1234.1). Try using np.float128 instead: Note however, that there are certain quirks with using extended precision. It may not work on Windows; you don’t actually get the full 128 bits of precision; and you might lose the precision whenever the number passes through pure … Read more

A tool to convert MATLAB code to Python

There are several tools for converting Matlab to Python code. The only one that’s seen recent activity (last commit from June 2018) is Small Matlab to Python compiler (also developed here: SMOP@chiselapp). Other options include: LiberMate: translate from Matlab to Python and SciPy (Requires Python 2, last update 4 years ago). OMPC: Matlab to Python (a bit outdated). Mat2py: Matlab … Read more