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


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

Re: how to check for NumericQ arbitrary data structure

From Christoph Lhotka <christoph.lhotka@fundp.ac.be>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: how to check for NumericQ arbitrary data structure
Date 2012-04-26 09:25 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jnb49m$5bf$1@smc.vnet.net> (permalink)
References <201204201144.HAA21808@smc.vnet.net> <201204210431.AAA29236@smc.vnet.net> <201204240932.FAA24447@smc.vnet.net>

Show all headers | View raw


Hi,

  I would like to add an "old"-style way of programming to tackle the 
problem:

data1 = {2, {Pi, 0.5}, {1/2, {I, 3 Sin[2]}, {6}}};
data2 = {a, {Pi, 0.5}, {1/2, {I, 3 Sin[2]}, {6}}};

testQ[expr_] := Block[{},
   If[
    Head[expr] === List,
    Do[testQ[expr[[i]]], {i, 1, Length[expr]}],
    If[! NumericQ[expr], Throw[False]]];
   Throw[True]
   ]

TestQ[expr_] := Catch[testQ[expr]]


TestQ[data1]
True

TestQ[data2]
False


Note, that TestQ is needed to catch the False thrown by testQ if 
!NumericQ returns True.

Best,

Christoph



On 04/24/2012 11:32 AM, Ted Sariyski 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
>
>

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


Thread

Re: how to check for NumericQ arbitrary data structure Christoph Lhotka <christoph.lhotka@fundp.ac.be> - 2012-04-26 09:25 +0000

csiph-web