Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7460 > unrolled thread
| Started by | "umberto" <umberto.prisco@unina.it> |
|---|---|
| First post | 2011-12-29 07:56 +0000 |
| Last post | 2011-12-30 12:18 +0000 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
DeleteCases "umberto" <umberto.prisco@unina.it> - 2011-12-29 07:56 +0000
Re: DeleteCases "Nasser M. Abbasi" <nma@12000.org> - 2011-12-30 12:09 +0000
Re: DeleteCases David Skulsky <edskulsky@gmail.com> - 2011-12-30 12:09 +0000
Re: DeleteCases Peter Breitfeld <phbrf@t-online.de> - 2011-12-30 12:16 +0000
Re: DeleteCases Szabolcs <szhorvat@gmail.com> - 2011-12-30 12:18 +0000
| From | "umberto" <umberto.prisco@unina.it> |
|---|---|
| Date | 2011-12-29 07:56 +0000 |
| Subject | DeleteCases |
| Message-ID | <jdh6g8$km5$1@smc.vnet.net> |
Dear All,
I have tables of this type:
{{{{0.912546, 0.1081}, -0.0206463}, {{0.186044, 0.835368}, -0.0214121},
{{0.0841709, -0.676585}, 1.59241}}, {{{-0.976965, -0.339164, -0.210989},
2.52712}, {{0.13978, -0.995106, 0.756386}, 1.09894}, {{-0.313147, -0.432759,
0.207548}, 1.53836}}}
I'd like to delete from the table elements of the type: {{x, x, ...., x}, y}
when y is not in the interval [-1, 1].
I was trying with DeleteCases, but with no success.
Could you, please, help me.
best regards
Umberto
[toc] | [next] | [standalone]
| From | "Nasser M. Abbasi" <nma@12000.org> |
|---|---|
| Date | 2011-12-30 12:09 +0000 |
| Message-ID | <jdk9l7$8a7$1@smc.vnet.net> |
| In reply to | #7460 |
On 12/29/2011 1:56 AM, umberto wrote:
> Dear All,
>
> I have tables of this type:
>
> {{{{0.912546, 0.1081}, -0.0206463}, {{0.186044, 0.835368}, -0.0214121},
> {{0.0841709, -0.676585}, 1.59241}}, {{{-0.976965, -0.339164, -0.210989},
> 2.52712}, {{0.13978, -0.995106, 0.756386}, 1.09894}, {{-0.313147, -0.432759,
> 0.207548}, 1.53836}}}
>
> I'd like to delete from the table elements of the type: {{x, x, ...., x}, y}
> when y is not in the interval [-1, 1].
> I was trying with DeleteCases, but with no success.
> Could you, please, help me.
> best regards
> Umberto
>
may be one way:
------------------------------------
cleanedData = DeleteCases[data, {x_, y_} /; y < -1 || y > 1, {2}]
-----------------------------------
{{{{0.912546, 0.1081}, -0.0206463},
{{0.186044,0.835368}, -0.0214121}},
{}}
If you do not like the empty {} entry left, you can remove it
----------------------------------------------
cleanedData = DeleteCases[cleanedData, {}]
-----------------------------------------------
{{{{0.912546, 0.1081}, -0.0206463},
{{0.186044, 0.835368}, -0.0214121}}}
--Nasser
[toc] | [prev] | [next] | [standalone]
| From | David Skulsky <edskulsky@gmail.com> |
|---|---|
| Date | 2011-12-30 12:09 +0000 |
| Message-ID | <jdk9m6$8ag$1@smc.vnet.net> |
| In reply to | #7460 |
In[20]:= ll={{{{0.912546,0.1081},-0.0206463},{{0.186044,0.835368},-0.0214121},{{0.0841709,-0.676585},1.59241}},{{{-0.976965,-0.339164,-0.210989},2.52712},{{0.13978,-0.995106,0.756386},1.09894},{{-0.313147,-0.432759,0.207548},1.53836}}}
Out[20]= {{{{0.912546,0.1081},-0.0206463},{{0.186044,0.835368},-0.0214121},{{0.0841709,-0.676585},1.59241}},{{{-0.976965,-0.339164,-0.210989},2.52712},{{0.13978,-0.995106,0.756386},1.09894},{{-0.313147,-0.432759,0.207548},1.53836}}}
In[21]:= ll=Flatten[ll,1]
Out[21]= {{{0.912546,0.1081},-0.0206463},{{0.186044,0.835368},-0.0214121},{{0.0841709,-0.676585},1.59241},{{-0.976965,-0.339164,-0.210989},2.52712},{{0.13978,-0.995106,0.756386},1.09894},{{-0.313147,-0.432759,0.207548},1.53836}}
In[22]:= DeleteCases[ll,x_/;Abs[x[[2]]]>1]
Out[22]= {{{0.912546,0.1081},-0.0206463},{{0.186044,0.835368},-0.0214121}}
[toc] | [prev] | [next] | [standalone]
| From | Peter Breitfeld <phbrf@t-online.de> |
|---|---|
| Date | 2011-12-30 12:16 +0000 |
| Message-ID | <jdka3i$8eo$1@smc.vnet.net> |
| In reply to | #7460 |
"umberto" wrote:
> Dear All,
>
> I have tables of this type:
>
> {{{{0.912546, 0.1081}, -0.0206463}, {{0.186044, 0.835368}, -0.0214121},
> {{0.0841709, -0.676585}, 1.59241}}, {{{-0.976965, -0.339164, -0.210989},
> 2.52712}, {{0.13978, -0.995106, 0.756386}, 1.09894}, {{-0.313147, -0.432759,
> 0.207548}, 1.53836}}}
>
> I'd like to delete from the table elements of the type: {{x, x, ...., x}, y}
> when y is not in the interval [-1, 1].
> I was trying with DeleteCases, but with no success.
> Could you, please, help me.
> best regards
> Umberto
I'll give your table the name tab. Then you might do the following:
Select[DeleteCases[#, {{__}, y_} /; Not[-1 <= y <= 1]] & /@
tab, (# != {}) &]
Out[]={{{{0.912546, 0.1081}, -0.0206463}, {{0.186044,
0.835368}, -0.0214121}}}
--
_________________________________________________________________
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de
[toc] | [prev] | [next] | [standalone]
| From | Szabolcs <szhorvat@gmail.com> |
|---|---|
| Date | 2011-12-30 12:18 +0000 |
| Message-ID | <jdka7c$8g1$1@smc.vnet.net> |
| In reply to | #7460 |
You can use DeleteCases[data, {x_, y_} /; Abs[y] > 1]
x_ will match anything, including a list (not just numbers).
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web