Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #9805 > unrolled thread
| Started by | Christoph Lhotka <christoph.lhotka@fundp.ac.be> |
|---|---|
| First post | 2012-04-26 09:25 +0000 |
| Last post | 2012-04-26 09:25 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: how to check for NumericQ arbitrary data structure Christoph Lhotka <christoph.lhotka@fundp.ac.be> - 2012-04-26 09:25 +0000
| From | Christoph Lhotka <christoph.lhotka@fundp.ac.be> |
|---|---|
| Date | 2012-04-26 09:25 +0000 |
| Subject | Re: how to check for NumericQ arbitrary data structure |
| Message-ID | <jnb49m$5bf$1@smc.vnet.net> |
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 top | Article view | comp.soft-sys.math.mathematica
csiph-web