MathGroup Archive 2009

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

Search the Archive

Re: Working with Lists

  • To: mathgroup at
  • Subject: [mg104358] Re: Working with Lists
  • From: Peter Breitfeld <phbrf at>
  • Date: Thu, 29 Oct 2009 02:55:48 -0500 (EST)
  • References: <hc927e$eca$>

BenT wrote:

> I have several practical problems which I need to solve, and
> understand, preferable in a generic matter well, before needing to
> apply them specifically pertaining to:
> using a "generic" example:
> f={{1,2,},{3,4,},{5,6},{7,8}}
> NOTE: the use of 1 thru 8 for the values is purely arbitrary so please
> to do not apply any "simplifications" based on their present values.
> I know have to obtain the sum of all of the elements in each of the
> lists by using
> Apply[Plus,f]
> and from it, I can use the Part function or "[[]]" method of obtaining
> each result as needed.
> asum=Apply[Plus,f][[1]]
> bsum=Apply[Plus,f][[2]]
> What I further need are methods to:
> (1) obtain separate lists, call them a and b which contain just the
> 1st and 2nd elements of each sublist respectively

The lists of the first and second elements are:


> (2) then after further, if eny modification of either list's data (a
> copletely separate issue), I need to know the method of how to merge
> them, and replace the original data.

> I know how to apply Rule's to transform data on a list of single
> elements, but not for "larger" lists.
> Consider this code:
> f={{0,1},{7,1},{12,2}}
> rd={1->1/4,2=1/2}
> How can I apply the rd "rule" (or any Rule) to just the second
> elements' 2nd values in the f list? And more importantly how are such
> things done generically?

Create a function which takes a pair:


Then use MapAt to apply it to the second Element of the list

MapAt[rdfund, f, 2]


> And someone please define distinct differences between:
> (1) list
> (2) sequence
> (2) vector
> (2) array
> (3) matrix/table

Vector is a list with exactly one pair of braces
Matrix is a list of vectors of equal length

There exist no symbols named Vector or Matrix, all are List, but
Mathematica can test the structure with the functions VectorQ and MatrixQ.

Array and Table are Mathematica functions to construct Lists, Matrices...

Sequence[a,b,c,...] represents a sequence of values. One out of many
other possibilities of use is the following:

Suppose you have a Function with several parameters, e.g.
f[x_,y_,z_]:=<some calculation>

and you want it to evaluate with several sets of values


then you can't write f[val1] because f needs three parameter but val1 is
the expression List[1,2,3] which is _one_ object for Mathematica. But
you can change the Head List to "nothing", what Sequence effectively
does; though


Hope I could help
Peter Breitfeld, Bad Saulgau, Germany --

  • Prev by Date: Re: Mathematica7 doesn't copy/paste metafile in vector format
  • Next by Date: ReplaceAll evaluation
  • Previous by thread: Re: Working with Lists
  • Next by thread: Distribution of state occupancies in a multistate Markov model