Re: sparse matrix question

• To: mathgroup at smc.vnet.net
• Subject: [mg56187] Re: sparse matrix question
• From: Paul Abbott <paul at physics.uwa.edu.au>
• Date: Mon, 18 Apr 2005 03:08:52 -0400 (EDT)
• Organization: The University of Western Australia
• References: <d3lrsq\$sef\$1@smc.vnet.net> <200504150847.EAA11518@smc.vnet.net> <200504160752.DAA24641@smc.vnet.net> <d3t39r\$8jt\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```In article <d3t39r\$8jt\$1 at smc.vnet.net>, DrBob <drbob at bigfoot.com>
wrote:

> l={{a,b},{c,d},{e,f}};
> p={3,4,6};
> SparseArray@
> Flatten[Transpose[{p,l}]/.{a_Integer,{b_,c_}}\[RuleDelayed]{Rule[{1,a},b],\
> Rule[{2,a},c]}]

A slightly more general approach is

Flatten[Transpose[{p, l}] /.
{a_Integer, d_} :>  MapIndexed[{First[#2], a} -> #1 & , d]]

> SparseArray[<\[InvisibleSpace]6\[InvisibleSpace]>,{2,6}]
>
> Normal@%
>
> {{0,0,a,c,0,e},{0,0,b,d,0,f}}
>
> %[[All,3]]
>
> {a,b}
>
> Bobby
>
> On Sat, 16 Apr 2005 03:52:10 -0400 (EDT), Ted Sariyski
> <tsariysk at craft-tech.com> wrote:
>
> > Hi,
> >
> > I have a list
> > l={{a,b},{c,d},{e,f}}
> > and a list of pointers  to the non-zero columns of a
> > sparse matrix e.g. p={3,4,6}:
> >      | 0 0 a c 0 d 0 ... |
> > m=    |                   |
> >       | 0 0 b d 0 e 0 ... |
> >
> > What is the best way to do this? How can I address a column in
> > mathematica?
> >
> > Thanks,
> > Ted
> >
> >
> >
> >
> >
> >
> >

--
Paul Abbott                                   Phone: +61 8 6488 2734
School of Physics, M013                         Fax: +61 8 6488 1014
The University of Western Australia      (CRICOS Provider No 00126G)
35 Stirling Highway
Crawley WA 6009                      mailto:paul at physics.uwa.edu.au
AUSTRALIA                            http://physics.uwa.edu.au/~paul

```

• Prev by Date: Re: How can I get a nonscalar logical variable into a compiled function?
• Next by Date: Re: Typesetting Mathematica code
• Previous by thread: Re: sparse matrix question
• Next by thread: Re: sparse matrix question