Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3116

Re: Problem with Position

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.news-service.com!newspump.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From Bob Hanlon <hanlonr@cox.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Problem with Position
Date Thu, 16 Jun 2011 08:00:40 +0000 (UTC)
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Sender steve@smc.vnet.net
Approved Steven M. Christensen <steve@smc.vnet.net>, Moderator
Message-ID <itcd78$csm$1@smc.vnet.net> (permalink)
Reply-To hanlonr@cox.net
Lines 56
NNTP-Posting-Date 16 Jun 2011 07:02:00 GMT
NNTP-Posting-Host c9e8f384.news.twtelecom.net
X-Trace DXC=RYog?MR]e_54c1ZETcjjP3C_A=>8kQj6==_1NR_H?JP=AS>5b;NHTB3EFiONJ7[Go6>=hIfPZOhL>
X-Complaints-To abuse@twtelecom.net
Xref x330-a1.tempe.blueboxinc.net comp.soft-sys.math.mathematica:3116

Show key headers only | View raw


Perhaps the numbers have more decimal places than what is displayed and you
 need to round to the precision of the index key.

choices = {0.123456, 0.654321, 0.785398};

data = Table[{
    RandomChoice[choices] + 10^-7*Random[],
    RandomReal[], RandomReal[]}, {10}];

Flatten@
 Position[N[Round[data[[All, 1]], 10^-6]],
  0.785398]

{2, 5, 6, 9}

Flatten@
   Position[N[Round[data[[All, 1]], 10^-6]], #] & /@
 choices

{{1, 3, 4, 8}, {7, 10}, {2, 5, 6, 9}}

Alternatively,

Flatten@
 Position[data[[All, 1]],
  _?(Abs[# - 0.785398] < 10^-6 &)]

{2, 5, 6, 9}

Table[
 Flatten@Position[data[[All, 1]],
   _?(Abs[# - c] < 10^-6 &)],
 {c, choices}]

{{1, 3, 4, 8}, {7, 10}, {2, 5, 6, 9}}


Bob Hanlon

---- "Dominic W=C3=B6rner" <dominic.woerner@mpi-hd.mpg.de> wrote:

=============
Hi,

I have to import data from a csv file. And I get a structure data[[rows]] ={first, second,...}.
Now I want to find the rows in which, say the first entry has a specific values.
By just looking at the data there are for example entries with value 0.785398.
But when I try Flatten@Position[data[[All,1]],0.785398] or with ToString[0.785398] I just get {}

What's the problem here?

Best,
Dominic

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: Problem with Position Bob Hanlon <hanlonr@cox.net> - 2011-06-16 08:00 +0000

csiph-web