MathGroup Archive 2003

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

Search the Archive

Re: expanding a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42626] Re: expanding a list
  • From: "Borut L" <gollum at email.si>
  • Date: Fri, 18 Jul 2003 05:25:22 -0400 (EDT)
  • References: <bf5ksa$mj0$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

I would do it like this

Flatten@MapThread[ Table[ #1, {#2}]&, {plist, flist}]

You can find out quickly what Table does, while MapThread goes into the two
lists and picks out the two correspoding elements. Flatten is needed here,
because withouht it the result would be a list of lists of length
Length[plist].


Bye,

Borut Levart
Slovenia


"Alan Kelly" <Alan.Kelly at tcd.ie> wrote in message
news:bf5ksa$mj0$1 at smc.vnet.net...
> Hi all,
> I believe that this is a rather elementary question, but I am not
> aware of a simple, elegant and efficient solution. I have searched
> the MathGroup archive, but with no success.
>
> I have two lists - both of the same length.  The first contains a
> list of probabilities. For example, suppose the list length is 4
> (although in practice it would be much longer) and is of the
> following form:
> plist = {0.252, 0.252, 0.257, 0.235}.
> The second contains a  list of integers:
> flist = {7,5,6,4}.
> I wish to take the first element of plist and replicate that value
> using the first element of flist.  Similarly for the remaining
> elements.
> I should finish with a list of length 7+5+6+4 or 22.
> Any suggestion please.
> Many thanks,
> Alan Kelly
> Trinity College Dublin
>



  • Prev by Date: Re: displaying a graphic without input
  • Next by Date: RE: expanding a list
  • Previous by thread: Re: expanding a list
  • Next by thread: RE: expanding a list