Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #14832 > unrolled thread
| Started by | Costa Bravo <q13a27tt@aol.com> |
|---|---|
| First post | 2013-06-13 06:32 +0000 |
| Last post | 2013-06-15 08:17 +0000 |
| Articles | 5 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Position Costa Bravo <q13a27tt@aol.com> - 2013-06-13 06:32 +0000
Re: Position "Alexander Elkins" <alexander_elkins@hotmail.com> - 2013-06-14 08:45 +0000
Re: Position "Dr. Wolfgang Hintze" <weh@snafu.de> - 2013-06-14 08:46 +0000
Re: Position Helen Read <readhpr@gmail.com> - 2013-06-14 08:53 +0000
Re: Position David Bailey <dave@removedbailey.co.uk> - 2013-06-15 08:17 +0000
| From | Costa Bravo <q13a27tt@aol.com> |
|---|---|
| Date | 2013-06-13 06:32 +0000 |
| Subject | Position |
| Message-ID | <kpbp24$95n$1@smc.vnet.net> |
How can I find the indices of all elements greaters than e.g. 2 of a vector.
t=RandomReal[{0,5},100]
Position[t,??]
--
Costa
[toc] | [next] | [standalone]
| From | "Alexander Elkins" <alexander_elkins@hotmail.com> |
|---|---|
| Date | 2013-06-14 08:45 +0000 |
| Message-ID | <kpel6p$hpv$1@smc.vnet.net> |
| In reply to | #14832 |
Use Condition(/;) on a Pattern named x matching any Real to test x for
Greater than 2.0 like so:
In[1]:=
Position[{1.4,3.5,2.1,-1.2},x_Real/;x>2.]
Out[1]=
{{2},{3}}
In[2]:=
FullForm[x_Real /; x > 2.]
Out[2]=
Condition[Pattern[x, Blank[Real]], Greater[x, 2.`]]
Or use PatternTest on an unnamed pattern matching any Real to test it for
Greater than 2.0 like so:
In[3]:=
Position[{1.4,3.5,2.1,-1.2},_Real?(#>2.&)]
Out[3]=
{{2},{3}}
In[4]:=
FullForm[_Real?(#>2.&)]
Out[4]//FullForm=
PatternTest[Blank[Real],Function[Greater[Slot[1],2.`]]]
"Costa Bravo" <q13a27tt@aol.com> wrote in message
news:kpbp24$95n$1@smc.vnet.net...
> How can I find the indices of all elements greaters than e.g. 2 of a
vector.
>
> t=RandomReal[{0,5},100]
> Position[t,??]
>
> --
> Costa
>
[toc] | [prev] | [next] | [standalone]
| From | "Dr. Wolfgang Hintze" <weh@snafu.de> |
|---|---|
| Date | 2013-06-14 08:46 +0000 |
| Message-ID | <kpel8m$hqg$1@smc.vnet.net> |
| In reply to | #14832 |
On 13 Jun., 08:32, Costa Bravo <q13a2...@aol.com> wrote:
> How can I find the indices of all elements greaters than e.g. 2 of a vector.
>
> t=RandomReal[{0,5},100]
> Position[t,??]
>
> --
> Costa
Not very elegant but it works:
In[52]:= t = RandomReal[{0, 5}, 10]
Out[52]= {3.6397213817178766, 4.7225642409045605, 1.3556422889069708,
\
2.9166466052152735, 1.9669329531284898, 4.151613177508343, \
0.5892783429281856, 4.990426012185576, 3.13226327938696, \
3.9424416959816426}
In[53]:= Flatten[(Position[t, #1] & ) /@ Select[t, #1 > 2 & ]]
Out[53]= {1, 2, 4, 6, 8, 9, 10}
Regards,
Wolfgang
[toc] | [prev] | [next] | [standalone]
| From | Helen Read <readhpr@gmail.com> |
|---|---|
| Date | 2013-06-14 08:53 +0000 |
| Message-ID | <kpelm0$ht7$1@smc.vnet.net> |
| In reply to | #14832 |
Here's one solution.
Map[Position[t, #] &, Select[t, # > 2 &]] // Flatten
Helen Read
University of Vermont
On 6/13/2013 2:32 AM, Costa Bravo wrote:
> How can I find the indices of all elements greaters than e.g. 2 of a vector.
>
> t=RandomReal[{0,5},100]
> Position[t,??]
>
> --
> Costa
>
[toc] | [prev] | [next] | [standalone]
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Date | 2013-06-15 08:17 +0000 |
| Message-ID | <kph7ua$2f2$1@smc.vnet.net> |
| In reply to | #14832 |
On 13/06/2013 07:32, Costa Bravo wrote:
> How can I find the indices of all elements greaters than e.g. 2 of a vector.
>
> t=RandomReal[{0,5},100]
> Position[t,??]
>
> --
> Costa
>
Flatten[Position[t, x_ /; x > 2]]
David Bailey
http://www.dbaileyconsultancy.co.uk
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web