Category: Python

PySide in Anaconda3

When using Matplotlib in Anaconda 3, and if you’re trying to use QT4Agg, you may get the error message ImportError: No module named ‘PySide’ To fix this, you can try (using your Anaconda3 pip) pip install pyside This will take several minutes and may require the prerequisites: sudo apt-get install libxext-dev python-qt4 qt4-dev-tools build-essential   […]

Python findpeaks

If you’re looking for a Python function that works like Matlab’s “findpeaks” checkout SciPy argrelmax. If you want to do a comparison in the same code, you can call Octave findpeaks using Oct2Py, or use the Matlab Python API in Matlab R2014b

Miniconda Python on Intel Edison

Since the Intel Edison is a 32-bit CPU, we use the 32-bit version. But first, we need to install GNU Tar because Busybox tar doesn’t have some needed tar options, and it’s not compatible with GNU tar archives (!). Since original writing, AlexT_Intel has put GNU tar in the opkg repository, so you can just […]

Python logging module versions to disk

I run Python massively in parallel with GNU Parallel across numerous remote PCs. I want to have the version numbers of the Python modules I’m using logged to disk. Here’s how I do so for Python 2.7 and 3.4

Travis CI SciPy requirements.txt

I have noticed that currently Travis CI has SciPy 0.9.0. That’s fine for most of my things (except savgol_filter which is new in 0.14.0) When I put SciPy>=0.9.0 in requirements.txt, even though Travis gets SciPy 0.9.0 from apt-get install scipy Travis still tries to pip install SciPy latest version. It’s been suggested by many to […]

Matplotlib ValueError on LogNorm plots

I was getting the error ValueError: Data has no positive values, and therefore can not be log-scaled. The issue is that I was setting vmin=0 in my pcolormesh() plot. By setting vmin=1 or some small positive value, your plots will work with norm=LogNorm() as expected.

Speed of Matlab vs. Python Numpy Numba

Here is a comparison on my Intel i7-2600 Sandy Bridge (3 year old) desktop PC. Python 3.4.2, Anaconda 2.1, iPython 2.2.0, Numpy 1.8.2 with Intel MKL import numpy as np A = np.matrix(np.random.randn(5000,5000)) B = np.matrix(np.random.randn(5000,5000)) %timeit A*B 1 loops, best of 3: 2.51 s per loop Matlab R2014b, also with Intel MKL A = […]

Python: Numba 0.15.1 has bug regression: doesn’t like “is not”

Update: this has been patched I’m waiting for the next release of Numba after 0.15.1. ————- In trying to write idiomatic Python, I use “None” like many people are taught to use NaN in languages such as Matlab–to indicate non-execution of command due to unused option or function result being undefined. The current (0.15.1) verson […]

Installing Python Pip on Intel Edison

Note: The current Yocto images only leave a few hundred MB under / while giving a couple GB free under /home. Be careful not to fill up / I may remap the Python libraries to /home. Assuming you’ve already added the unofficial repository, I did the following: opkg install python-pip cd curl -o […]

Sparse Matrices in Python from Matlab R2014b

First of all, you can’t pass sparse matrices, so you have to have enough RAM to hold the full matrix and probably a copy or two of it. This is more just to show how it could be done, and hope that the Mathworks will improve the passing of variables in future releases of Matlab. […]