Re: Part

• To: mathgroup at smc.vnet.net
• Subject: [mg2912] Re: [mg2890] Part
• From: brucec (Bruce Carpenter)
• Date: Tue, 9 Jan 1996 02:18:54 -0500

```>w={{1,2,3},{4,5,6},{7,8,9}}
>npos={2,1}
>
>npos is the position of the element I need.
>
>w[[npos]]
>
>does not work, as it returns the second and the first
>line.
>
>w[[ npos[[1]],npos[[2]] ]]
>
>does the wanted thing, but I would prefer a shorter and
>more general way.
>
>Hans Friedrich Steffani

Hi Hans--

Here is another way to solve your problem.  A top-level mechanism has been
provided to specify a sequence of variables:

In[9]:=

w={{1,2,3},{4,5,6},{7,8,9}};
npos={2,1};

In[11]:=
w[[##]]& @@ npos

Out[11]=
4

In a pure function, # specifies the first variable, #n specifies the nth
variable, ## the sequence of all variables, and ##n the sequence of
variables starting with the nth one.
(This is documented in Wolfram's Mathematica: A System for Doing
Mathematics by Computer.)
I am not critical of the use of Sequence to do this, I just prefer to use
documented commands when possible.

Best Regards,

Bruce Carpenter

==== [MESSAGE SEPARATOR] ====

```

• Prev by Date: 2.2.3 Running under Win 95
• Next by Date: Re: Part
• Previous by thread: Re: Part
• Next by thread: Re: Part