MathGroup Archive 1999

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

Search the Archive

Re: A better way to decimate a file??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg21354] Re: A better way to decimate a file??
  • From: Martin Kraus <Martin.Kraus at informatik.uni-stuttgart.de>
  • Date: Wed, 29 Dec 1999 14:15:42 -0500 (EST)
  • Organization: Institut fuer Informatik, Universitaet Stuttgart
  • References: <849j3v$pgm@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Rob Peterson wrote:
> 
> I start with a list y that I need to decimate (sp?).  I've looked thru
> the book and the only list function I can find to dump list elements
> is the Drop[] function.  But, the best I can do is get rid of half of
> the elements at a time.  I want to decimate this list by 16, ie I want
> to dump 15 of every 16 entries.  So, I dump half of them four times.
> This seems to work but I figure the pros hanging in this group will
> know a much more elegant way to do this.  I did this:
> 
> (* start with y as the list  and ly = Length[y]  *)
> 
> y2 = Drop[y, {1, ly, 2}]; ly2 = Length[y2]
> 
> y4 = Drop[y2, {1, ly2, 2}]; ly4 = Length[y4]
> 
> and so on
> 
> So how should it really be done?  I'd like to be able to decimate by
> non-binary numbers too.
> 
> Thanks, Rob

Hmmm, I guess the problem here is that you tried to drop elements,
i.e. that you tried to modify an existing list.
A better approach in this case is to ask: How can you construct 
such a new list?

One useful command to construct lists is Table, for example:

y = {a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u}

Table[y[[i]], {i, 1, Length[y], 5}]

This constructs a list with every fifth element. (You can replace
the 5 by any integer > 0.)

Another constructive way is to Take every fifth element:

Take[y, {1, Length[y], 5}]

or shorter (as -1 is the last element):

Take[y, {1, -1, 5}]

Very similar to this is the command

Flatten[Partition[y, 1, 5], 1]

This is very close to a modification of y (with 
Transpose[Partition[y, 5, 5, 1]] ) and dropping everything
we dont want:

First[Transpose[Partition[y, 5, 5, 1]]]

(First[Transpose[Partition[y, 5]]] is almost the same but 
does not include the u.)

What way should you use? I think the Table approach
is the most useful. However, using Transpose and Partition
is also an extremely powerful technique if you have to work
with lists.

Hope that helps

Martin Kraus


  • Prev by Date: RE: A better way to decimate a file??
  • Next by Date: Re: Fonts and WinNT
  • Previous by thread: RE: A better way to decimate a file??
  • Next by thread: Re: A better way to decimate a file??