       RE: Position on a List

• To: mathgroup at smc.vnet.net
• Subject: [mg12890] RE: [mg12845] Position on a List
• Date: Wed, 24 Jun 1998 03:44:14 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Idoia Aguirre  wrote:
|
| When I do:   Position[{1/A, A}, A] |
| I obtain:    {{1,1},{2}}
|
| But I would like to obtain only :  {{2}} |

You need to give Position a levelspec as a third argument.

In:=
?Position
"Position[expr, pattern] gives a list of the positions at which objects
\ matching pattern appear in expr. Position[expr, pattern, levspec]
finds only  \
objects that appear on levels specified by levspec."

You need to specify levspec=1  as in the line below.

In:=
Position[{1/A,A},A,1]
Out=
{{2}}

_________________________________
Lets look at this a little closer with another example. With the default
levelspec we get the position of every A. In shows us that the
default levlspec must be Infinity.

In:=
Position[{1/(1+A), 1/A, A}, A]
Out=
{{1,1,2},{2,1},{3}}

In:=
Position[{1/(1+A), 1/A, A}, A, Infinity] Out=
{{1,1,2},{2,1},{3}}

If we specify levelspec=2 we get all positions where A can be found from
level 1 through level 2.

In:=
Position[{1/(1+A), 1/A, A}, A, 2]
Out=
{{2,1},{3}}

If we specify levelspec=1 we get all positions where A can at Level 1.

In:=
Position[{1/(1+A), 1/A, A}, A, 1]
Out=
{{3}}

If we specify levelspec={2} we get all positions where A can be found at
level 2.

In:=
Position[{1/(1+A), 1/A, A}, A, {2}]
Out=
{{2,1}}

Ted Ersek

```

• Prev by Date: Re: Re: Split in Mathematica 2.2
• Next by Date: Piecewise defined functions
• Previous by thread: Re: Position on a List
• Next by thread: Mailing List and Newsgroup 6/17-6/21/98