Re: Efficient Replacement Rules to Matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg21746] Re: Efficient Replacement Rules to Matrix?
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Thu, 27 Jan 2000 22:56:29 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <86mdud$2fq@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, look if repmat1 = repmat /. Rule -> List; Set[Part[matrix, Sequence @@ #1], #2] & @@@ repmat1 is not faster. Hope that helps Jens Roger Jones wrote: > > What is the most efficient (in terms of time) method to transform a set > of replacement rules to a matrix. For example, I have: > > matrix = ZeroMatrix[5]; > repmat = {{1, 1} -> 4., {5, 5} -> 3,{4, 4} -> 10,{2, 2} -> 2 + I 6, {3, > 3} -> 40.}; > > and I transfor to a matrix thus: > > matrix = ReplacePart[matrix, Sequence @@ #]) & /@ ( > {Last[#], #[[1]]} & /@ matrix); > > But for large matrices this is quite slow! Is there a more efficient > method? > > I then will form a matrix product with this sparse matrix: > result= matrix.avector and this is indeed my goal. > > I would appreciate any ideas on this matter. > Many thanks! > > -Roger Jones > > PS This comes to light in the context of using the new Mathematica > function "SparseLinearSolve"