scipy.special import issue

By default, “import scipy” does not import any subpackage. There are too many subpackages with large Fortran extension modules that are slow to load. I do not recommend doing import scipy or the abbreviated import scipy as sp. It’s just not very useful. Use from scipy import special, from scipy import linalg, etc.

Check if two scipy.sparse.csr_matrix are equal

Can we assume they are the same shape? In [202]: a=sparse.csr_matrix([[0,1],[1,0]]) In [203]: b=sparse.csr_matrix([[0,1],[1,1]]) In [204]: (a!=b).nnz==0 Out[204]: False This checks the sparsity of the inequality array. It will give you an efficiency warning if you try a==b (at least the 1st time you use it). That’s because it has to test all those zeros. … Read more

How to install python packages without root privileges?

You don’t need root privileges to install packages in your home directory. You can do that with a command such as pip install –user numpy or from source python setup.py install –user See https://stackoverflow.com/a/7143496/284795 The first alternative is much more convenient, so if the server doesn’t have pip or easy_install, you should politely ask the … Read more

Scipy/Numpy FFT Frequency Analysis

I think you don’t need to do fftshift(), and you can pass sampling period to fftfreq(): import scipy import scipy.fftpack import pylab from scipy import pi t = scipy.linspace(0,120,4000) acc = lambda t: 10*scipy.sin(2*pi*2.0*t) + 5*scipy.sin(2*pi*8.0*t) + 2*scipy.random.random(len(t)) signal = acc(t) FFT = abs(scipy.fft(signal)) freqs = scipy.fftpack.fftfreq(signal.size, t[1]-t[0]) pylab.subplot(211) pylab.plot(t, signal) pylab.subplot(212) pylab.plot(freqs,20*scipy.log10(FFT),’x’) pylab.show() from … Read more

Python double free error for huge datasets

After discussions on the same issue on the Numpy Github page (https://github.com/numpy/numpy/issues/2995) it has been brought to my attention that Numpy/Scipy will not support such a large number of non-zeros in the resulting sparse matrix. Basically, W is a sparse matrix, and Q (or np.log(Q)-1) is a dense matrix. When multiplying a dense matrix with … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)