[SciPy-user] Sparse indexing workarounds

Håkan Jakobsson hakan.jakobsson@gmail....
Sat Apr 14 06:55:00 CDT 2007


Yes, I acctually knew that but forgot to mention. Sorry. In any case, would
this kind of functionality not be very nice to have in the standard sparse
package? For one I find  that pysparse really doesn't install without fuzz.
I couldn't get it to work with Python 2.5 and had to install 2.4 on my Mac
in order to do so. At uni we've been trying to get it to work on some Linux
boxes but no luck. Maybe this functionality is already planned for in
sparse, otherwise that's my suggestion. Unfortunately  I'm not savvy enough
(yet) when it comes to python, but when I am I'll be happy to help out. :)
/Håkan

On 4/14/07, Bill Baxter <wbaxter@gmail.com> wrote:
>
> Ack!  Pysparse's update_add_mask is bugged!
>
> In [188]: K = arange(12).reshape((3,4))
> In [189]: L = spmatrix.ll_mat(10,10)
> In [190]: L.update_add_mask(K, [7,8,9],[3,4,5,6], [True]*3,[True]*4)
> In [191]: todense(L)
> Out[191]:
> array([[  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   0.,   3.,   6.,   9.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   1.,   4.,   7.,  10.,   0.,   0.,   0.],
>        [  0.,   0.,   0.,   2.,   5.,   8.,  11.,   0.,   0.,   0.]])
> In [192]: K
> Out[192]:
> array([[ 0,  1,  2,  3],
>        [ 4,  5,  6,  7],
>        [ 8,  9, 10, 11]])
>
> Notice how K got transposed and reshaped.  To make it work properly
> you have to do
>
>     L.update_add_mask (K.T.reshape(3,4), [7,8,9],[3,4,5,6],
> [True]*3,[True]*4)
>
> --bb
>
>
> On 4/10/07, Håkan Jakobsson <hakan.jakobsson@gmail.com> wrote:
> > You can use pysparse instead of sparse. The update_add_mask function
> will do
> > the trick.
> > /Håkan J
> >
> >
> > On 4/10/07, Robert Cimrman < cimrman3@ntc.zcu.cz> wrote:
> > > Bill Baxter wrote:
> > > > Does anyone have an easy (and efficient way) to update a submatrix
> of
> > > > a big sparse matrix?
> > > >
> > > >   K = scipy.sparse.lil_matrix(bigN,bigN)
> > > >   ...
> > > >   conn = [1,4,11,12]
> > > >   K[ix_(conn,conn)] += elemK
> > > >
> > > > where elemK is a 4x4 dense matrix.
> > > >
> > > > This kind of thing is very commonly needed in FEM codes for
> assembling
> > > > the global stiffness matrix.  But sparse doesn't seem to support
> > > > either += or indexing with the open grid of indices returned by ix_.
> > >
> > > You may have a look at
> > > http://ui505p06-mbs.ntc.zcu.cz/sfe/FEUtilsExample
> > > it uses CSR matrix though...
> > >
> > > r.
> > > _______________________________________________
> > > SciPy-user mailing list
> > > SciPy-user@scipy.org
> > > http://projects.scipy.org/mailman/listinfo/scipy-user
> > >
> >
> >
> > _______________________________________________
> > SciPy-user mailing list
> > SciPy-user@scipy.org
> > http://projects.scipy.org/mailman/listinfo/scipy-user
> >
> >
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20070414/7f177c1e/attachment.html 


More information about the SciPy-user mailing list