Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: Package to 'graft' Lists onto Matrices

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87739] Re: Package to 'graft' Lists onto Matrices
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Wed, 16 Apr 2008 05:06:01 -0400 (EDT)

On 4/15/08 at 5:52 AM, robertprincewright at yahoo.com (robert
prince-wright) wrote:

>I've been looking at Join[ ], Append[ ], Insert[ ], etc. and wonder
>if someone has written a package that allows an Mathematica user to
>add Lists as rows and columns to form a new matrix.

>It seems a little daft that that you need to use MapThread and
>Append to simply graft a row onto an existing matrix!

Join works just fine for adding a row. For example,

In[19]:= m = Partition[Range[9], 3];
data = RandomInteger[{0, 4}, 3]

Out[20]= {2,0,0}

In[21]:= Join[m, {data}]

Out[21]= {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {2, 0, 0}}

or if I wanted to add a column I could do

In[22]:= Transpose@Join[Transpose@m, {data}]

Out[22]= {{1, 2, 3, 2}, {4, 5, 6, 0}, {7, 8, 9, 0}}


  • Prev by Date: Re: smart change of variables?
  • Next by Date: Re: smart change of variables?
  • Previous by thread: Re: Package to 'graft' Lists onto Matrices
  • Next by thread: Re: Re: Package to 'graft' Lists onto Matrices