MathGroup Archive 2011

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

Search the Archive

Re: Nested List Abs[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121042] Re: Nested List Abs[]
  • From: Heike Gramberg <heike.gramberg at gmail.com>
  • Date: Wed, 24 Aug 2011 07:50:37 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201108240714.DAA11365@smc.vnet.net>

There are multiple ways to do this. Suppose list is your list of integer 
pairs, e.g.

list = RandomInteger[{0, 5}, {20, 2}]

then all of the expressions below should give you the set of integer 
pairs with distance <=1:

Select[list, (Abs[#[[1]] - #[[2]]] <= 1 &)]

Cases[list, {a_, b_} /; Abs[a - b] <= 1]

Pick[list, Abs[#1 - #2] & @@@ list, a_ /; a <= 1]

DeleteCases[list, {a_, b_} /; Abs[a - b] > 1]


Heike


On 24 Aug 2011, at 09:14, Sam Korn wrote:

> I have a list, and each element of the
> list is a sublist with two integers. How do I delete from the larger
> list any integer pair whose numerical distance apart is greater than
> one? I'd been trying to map Abs[Subtract[#1,#2]]&<1 over the list, but
> so far that hasn't worked.
>
> Any suggestions?
>
> Sent from my iPhone
>





  • Prev by Date: Re: Nested List Abs[]
  • Next by Date: Re: Getting 3d printable models out of 3d graphics in Mathematica
  • Previous by thread: Nested List Abs[]
  • Next by thread: Re: Nested List Abs[]