[SciPy-user] math operations on sparse matrices
Sat Feb 21 19:33:48 CST 2009
On Sat, Feb 21, 2009 at 6:43 PM, Stéfan van der Walt <firstname.lastname@example.org> wrote:
> 2009/2/21 <email@example.com>:
>> I have a (dok) sparse distance matrix and I would like to take the
>> exponential of the distances
> I guess you could just as well switch to dense matrices then, since
> exp(0) is no longer zero.
> If you just want to change the non-zero values, you can use
> x.data = np.exp(x.data)
That was also my first guess, however
<50x50 sparse matrix of type '<type 'numpy.float64'>'
with 208 stored elements in Dictionary Of Keys format>
Traceback (most recent call last):
File "<pyshell#78>", line 1, in <module>
line 429, in __getattr__
AttributeError: data not found
For now this seems to work pretty fast
Mexp = M.copy()
Mexp.update(((k,exp(-v)) for k,v in M.iteritems()))
But I'm not sure I know what I'm doing.
What I'm trying to do is something like OLS with a sparse X'X matrix
(kernel rigdge regression).
The next step are:
alpha = sparse.linalg.minres(M,y)
yhat = M1.matmat(alpha)
>From the graphical results it seems to work, but since this is my
first try with scipy.sparse.linalg, I'm not sure what the methods to
More information about the SciPy-user