Message from discussion
how to check for NumericQ arbitrary data structure
Received: by 10.68.213.106 with SMTP id nr10mr1522238pbc.2.1335329033021;
Tue, 24 Apr 2012 21:43:53 -0700 (PDT)
MIME-Version: 1.0
Path: r9ni95593pbh.0!nntp.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!newspump.sol.net!posts.news.twtelecom.net!nnrp3.twtelecom.net!not-for-mail
From: Bob Hanlon <hanlonr...@gmail.com>
Newsgroups: comp.soft-sys.math.mathematica
Subject: Re: how to check for NumericQ arbitrary data structure
Date: Wed, 25 Apr 2012 04:41:08 +0000 (UTC)
Organization: Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Sender: st...@smc.vnet.net
Approved: Steven M. Christensen <st...@smc.vnet.net>, Moderator
Message-ID: <jn7v94$6gp$1@smc.vnet.net>
References: <201204201144.HAA21808@smc.vnet.net>
Lines: 32
NNTP-Posting-Date: 25 Apr 2012 04:43:52 GMT
NNTP-Posting-Host: e7679058.news.twtelecom.net
X-Trace: DXC=c[LBZN6S8\39g9ZDEYmh=8C_A=>8kQj6=2f3;U>_oji9>N`7d;`QI18EFiONJ7[Go6GL`DIhRCBg9
X-Complaints-To: abuse@twtelecom.net
myNumericQ[data_] := VectorQ[Flatten[data], NumericQ]
data = {a, {b, c}, {d, {e, f}, {g}}};
sub = Thread[{a, b, c, d, e, f, g} -> Hold[RandomInteger[{0, 9}]]] //
ReleaseHold
{a -> 6, b -> 9, c -> 1, d -> 5, e -> 1, f -> 1, g -> 4}
data // myNumericQ
False
data /. sub // myNumericQ
True
Bob Hanlon
On Tue, Apr 24, 2012 at 5:32 AM, Ted Sariyski <tsari...@craft-tech.com> wrote:
> Hi,
> I have a data structure e.g. {a,{b,c},{d,{e,f},{g}}}, which I want to
> check for NumericQ. For vectors and matrices I can use
> VectorQ[x,NumericQ] or MatrixQ[x,NumericQ]. Is there a way to check an
> arbitrary data structure that all elements are NumericQ or I have to
> construct a function for each data structure?
> Thanks in advance,
> --Ted
>