def reconstruct_columns(W, B):
W = W.copy()
for i in range(W.shape[1]):
C = W[:, i]
M = isntnan(C)
if sum(M) != C.shape[0]:
coeffs = dot(linalg.pinv(B[M,:]), C[M])
W[:, i] = dot(B, coeffs)
return W