Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

RE: Position on a List

  • To: mathgroup at smc.vnet.net
  • Subject: [mg12890] RE: [mg12845] Position on a List
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • 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[1]:=
?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[2]:=
Position[{1/A,A},A,1]
Out[2]=
{{2}}

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

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


In[4]:=
Position[{1/(1+A), 1/A, A}, A, Infinity] Out[4]=
{{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[5]:=
Position[{1/(1+A), 1/A, A}, A, 2]
Out[5]=
{{2,1},{3}}

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

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

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

In[7]:=
Position[{1/(1+A), 1/A, A}, A, {2}]
Out[7]=
{{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