Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2001
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2001

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

Search the Archive

Re: matrix

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28412] Re: matrix
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Mon, 16 Apr 2001 23:54:16 -0400 (EDT)
  • References: <9bb759$92p@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Some timings, and a different and a new, faster way

mat1=Block[{mat = Take[IdentityMatrix[4000], All, 1220]},
      mat[[All, All]] = 0;
mat[[Range[216, 220], All]] = 1; mat];//Timing     (*Allan Hayes1*)

mat2=PadRight[Table[1,{5},{1220}],{4000,1220},0,{215,0}];//Timing    (*Carl
Woll1*)

mat3=PadRight[Table[1,{5},{1220}],{4000,1220},0,{215,0}];//Timing  (*Carl
Woll2*)

mat4=PadRight[Table[1,{5},{1220}],{4000},
        Table[0,{1},{1220}],{215}];//Timing     (*Allan Hayes2*)

mat1===mat2===mat3===mat4

{20.44 Second,Null}

{3.29 Second,Null}

{2.25 Second,Null}

{0.11 Second,Null}

True

And the direct approach from poupoulinou:

mat5=Block[{m0 = Table[0,{1220}],
m1 = Table[1,{1220}]}, Table[If[216 <= i <= 220, m1, m0],{i,1,4000}]
        ];//Timing

{3.73 Second,Null}

mat1===mat5

True

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Su Su Win" <susuwin at post.kek.jp> wrote in message
news:9bb759$92p at smc.vnet.net...
> Hello,
>
> How can I make a matrix (4000x1220) with zeros except that all the values
at
> 216th to 220th rows are ones.
> Thank you very much in advance.
> Regards, Win
>
>
>
>




  • Prev by Date: Re: Determining if a directed graph is a rooted tree
  • Next by Date: MatrixTemplate (was SpecialMatrix)
  • Previous by thread: Re: matrix
  • Next by thread: Re: Flip a rule