Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4560
| From | "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Nested List Abs[] |
| Date | 2011-08-25 11:06 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j35abf$obp$1@smc.vnet.net> (permalink) |
| References | <j328jc$b4n$1@smc.vnet.net> |
On Wed, 24 Aug 2011 08:18:04 +0100, Sam Korn <sam@kornfamily.com> 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
>
In[1] :=
list = RandomInteger[{-5, 5}, {10, 2}]
Out[1] =
{{-4, -4}, {-2, 3}, {-3, -2}, {5, -1}, {5, 2}, {4, 0}, {3, 2}, {-5, -5},
{-2, -1}, {-5, -5}}
In[2] :=
DeleteCases[list, p_List /; Abs[Subtract @@ p] > 1, {1}]
Out[2] =
{{-4, -4}, {-3, -2}, {3, 2}, {-5, -5}, {-2, -1}, {-5, -5}}
In[3] :=
posns = Position[list, p_List /; Abs[Subtract @@ p] > 1, {1}];
Delete[list, posns]
Out[4] =
{{-4, -4}, {-3, -2}, {3, 2}, {-5, -5}, {-2, -1}, {-5, -5}}
In[5] :=
mask = Abs[Subtract @@ #] <= 1 & /@ list;
Pick[list, mask]
Out[6] =
{{-4, -4}, {-3, -2}, {3, 2}, {-5, -5}, {-2, -1}, {-5, -5}}
Sent from my PC
Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread
Nested List Abs[] Sam Korn <sam@kornfamily.com> - 2011-08-24 07:18 +0000 Re: Nested List Abs[] Ray Koopman <koopman@sfu.ca> - 2011-08-24 11:53 +0000 Re: Nested List Abs[] "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-08-25 11:06 +0000
csiph-web