run code error with numpy and scipy
meInvent bbird
jobmattcon at gmail.com
Thu Jun 9 02:02:05 EDT 2016
when i run code in window has an error not a valid win32 dll
then i install scipy first in this site, then install numpy-mkl
all python 2.7 and win32
http://www.lfd.uci.edu/~gohlke/pythonlibs/
then i run code below, got error , and captured screen in this link
https://drive.google.com/file/d/0Bxs_ao6uuBDUQXROd2VqSURGa00/view?usp=sharing
import numpy as np
from scipy.sparse.linalg import svds
from functools import partial
from scipy.sparse import csr_matrix
def emsvd(Y, k=None, tol=1E-3, maxiter=None):
if k is None:
svdmethod = partial(np.linalg.svd, full_matrices=False)
else:
svdmethod = partial(svds, k=k)
if maxiter is None:
maxiter = np.inf
muhat = np.nanmean(Y, axis=0, keepdims=1)
valid = np.isfinite(Y)
Y_hat = np.where(valid, Y, muhat)
halt = False
ii = 1
v_prev = 0
while not halt:
U, s, Vt = svdmethod(Y_hat - muhat)
Y_hat[~valid] = (U.dot(np.diag(s)).dot(Vt) + muhat)[~valid]
muhat = Y_hat.mean(axis=0, keepdims=1)
v = s.sum()
if ii >= maxiter or ((v - v_prev) / v_prev) < tol:
halt = True
ii += 1
v_prev = v
return Y_hat, muhat, U, s, Vt
A = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]])
emsvd(A)
np.nanmean(A, axis=0, keepdims=1)
More information about the Python-list
mailing list