MathGroup Archive 1999

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

Search the Archive

Re: Position of element in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16412] Re: Position of element in a list
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Sat, 13 Mar 1999 02:21:33 -0500
  • Organization: University of Western Australia
  • References: <7bt665$ndn@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Roger Mason wrote:

> I want to find the Position[] of negative elements in a list. 
> The obvious methods do not work:
> 
> Position[{-1, 3, -2, 1}, -_]
> 
> and
> 
> Position[{-1, 3, -2, 1}, -x_]
> 
> return
> 
> {}

The reason is that -1 is an atomic expression (whereas -x is not).

In[1]:= FullForm[{-1,-x}]

Out[1]//FullForm= List[-1, Times[-1, x]]
 
> So how do I perform this apparently simple task?

Use a test.  E.g.,

In[2]:= Position[{-1, 3, -2, 1}, _?Negative]

Out[2]= {{1}, {3}}

Cheers,
	Paul

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia           
Nedlands WA  6907                     mailto:paul at physics.uwa.edu.au 
AUSTRALIA                        http://www.physics.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: Re: Why () around Function in pattern?
  • Next by Date: Re: planar polygon plot
  • Previous by thread: Re: Position of element in a list
  • Next by thread: FFT