python version of K-SVD algorithm