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

MathGroup Archive 2007

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

Search the Archive

Re: How to construct a vector whose elements are also vectors?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg82841] Re: How to construct a vector whose elements are also vectors?
  • From: Thomas E Burton <tburton at brahea.com>
  • Date: Thu, 1 Nov 2007 05:11:32 -0500 (EST)

Most of us would probably form a single nested list of initialized  
values like this,

m=Table[values[i,j,k],{i,10},{j,10},{k,2}]

replacing the function values with whatever works for us. Or if we  
want to initialize with zeros,

m = Table[0, {10}, {10}, {2}]

or, using one of version 6's apparently redundant new functions,

m=ConstantArray[0,{10,10,2}]

In any case, we can access or update the first two elements with the  
Part function

Part[m,1,1]
m[[1,1]]
m[[1,1]]={1,0}

Following your example more closely, I could write

Table[(stat[i]=ConstantArray[0,{10,2}]),{i,10}]

and access the first two elements with

stat[1][[1]]

but now I cannot update these elements alone with Part, which will  
not accept stat[1] as an argument. Instead I can use ReplacePart:

ReplacePart[stat[1], 1 -> {1, 0}]

Note that elements of stat are accessed by a mixture of arguments (in  
single brackets) and part specs (in double brackets), whereas in my  
first example above, elements of m are accessed only by part specs.  
You may get an eyeful of recommendations about how to mix and match  
these two types of access from more expert users, so I'll sit back  
and watch.


  • Prev by Date: Re: Re: Easy Mapping problem that has me stumped!
  • Next by Date: Re: Issue with Locator's crosshairs object
  • Previous by thread: Re: How to construct a vector whose elements are also vectors?
  • Next by thread: Re: How to construct a vector whose elements are also vectors?