From: Francisco Gutierrez on
Dear Group:
Suppose I have a list of ordered integers:
example={1,5,7,9}
Based on it, I want to generate a list of the form:
{#[[1]], #[[5]],#[[7]],#[[9]]}

I tested with simple things like:
Table[#[[example[[i]]]], {i,1,Length[example]}]
to no avail.

How can I do it?
From: Patrick Scheibe on
Hi,

the problem is not that it doesn't work. The problem is, that the parts
of # you want to acces doesn't exist (except for the first one #[[1]]).
Therefore,

example = {1, 5, 7, 9};
Table[#[[i]], {i, example}]

works as expected. Without knowing what you want to do it's quite hard
to help you here.

Cheers
Patrick

On Fri, 2010-07-16 at 05:16 -0400, Francisco Gutierrez wrote:
> Dear Group:
> Suppose I have a list of ordered integers:
> example={1,5,7,9}
> Based on it, I want to generate a list of the form:
> {#[[1]], #[[5]],#[[7]],#[[9]]}
>
> I tested with simple things like:
> Table[#[[example[[i]]]], {i,1,Length[example]}]
> to no avail.
>
> How can I do it?
>


From: Bob Hanlon on

data = Array[x, 10]

{x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10)}

example = {1, 5, 7, 9};

data[[example]]

{x(1),x(5),x(7),x(9)}

#[[example]] &[data]

{x(1),x(5),x(7),x(9)}


Bob Hanlon

---- Francisco Gutierrez <fgutiers2002(a)yahoo.com> wrote:

=============
Dear Group:
Suppose I have a list of ordered integers:
example={1,5,7,9}
Based on it, I want to generate a list of the form:
{#[[1]], #[[5]],#[[7]],#[[9]]}

I tested with simple things like:
Table[#[[example[[i]]]], {i,1,Length[example]}]
to no avail.

How can I do it?


From: magma on
On Jul 16, 11:16 am, Francisco Gutierrez <fgutiers2...(a)yahoo.com>
wrote:
> Dear Group:
> Suppose I have a list of ordered integers:
> example={1,5,7,9}
> Based on it, I want to generate a list of the form:
> {#[[1]], #[[5]],#[[7]],#[[9]]}
>
> I tested with simple things like:
> Table[#[[example[[i]]]], {i,1,Length[example]}]
> to no avail.
>
> How can I do it?

If i understand your question....
it seems you just forgot to put the &, which must appear somewhere
after all.

example = {1, 5, 7, 9} (* list of parts *)
arg = {w, e, r, t, y, u, i, o, p} (*an argument with 9 parts*)
Table[#[[example[[ii]]]], {ii, 1, Length[example]}] &[arg]

will give you

{w, y, i, p}

that is: a list of the first, fifth, seventh and ninth part of the
argument

From: David Bailey on
On 16/07/10 12:00, Bob Hanlon wrote:
> data = Array[x, 10]
>
> {x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10)}
>
>

I guess you typed that in rather than generating it with Mathematica :)


In[2]:= data = Array[x, 10]

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

David Bailey

http://www.dbaileyconsultancy.co.uk