MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Efficient Replacement Rules to Matrix?


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"


  • Prev by Date: Re: Could this be improved?
  • Next by Date: Re: magic pen
  • Previous by thread: Re: Efficient Replacement Rules to Matrix?
  • Next by thread: Re: Efficient Replacement Rules to Matrix?