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


Groups > comp.soft-sys.math.mathematica > #9800 > unrolled thread

Re: how to check for NumericQ arbitrary data structure

Started byAlexei Boulbitch <Alexei.Boulbitch@iee.lu>
First post2012-04-26 09:30 +0000
Last post2012-04-26 09:30 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Re: how to check for NumericQ arbitrary data structure Alexei Boulbitch <Alexei.Boulbitch@iee.lu> - 2012-04-26 09:30 +0000

#9800 — Re: how to check for NumericQ arbitrary data structure

FromAlexei Boulbitch <Alexei.Boulbitch@iee.lu>
Date2012-04-26 09:30 +0000
SubjectRe: how to check for NumericQ arbitrary data structure
Message-ID<jnb4k7$5h2$1@smc.vnet.net>
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

Hi, Ted,

You did not specify, what exactly do you need to have as the result. You may want simply
to have
1) True, if all terms are numeric and False if any of them are non-numeric
or
2) you may want say, to preserve the structure of the original list, in which True and False
occupy the places of numeric and non-numeric items.

The first case is simple, since you can flatten the initial list
Try this function:

numericCheck[lst_List] := And @@ NumericQ /@ Flatten[lst];

For example, here are three lists with the structure you have specified:

lst1 = {a, {b, c}, {d, {e, f}, {g}}};
lst2 = {0.136, {0.683, 0.123}, {0.1867, {0.203, 0.493}, {0.5369}}};
lst3 = {0.136, {0.683, 0.123}, {0.1867, {a, 0.493}, {0.5369}}};

Among them only the lst2 is numeric, while lst3 has a variable "a" instead of the number in the position {3,2,1}. Let us check

numericCheck /@ {lst1, lst2, lst3}

{False, True, False}

Have fun, Alexei

Alexei BOULBITCH, Dr., habil.
IEE S.A.
ZAE Weiergewan,
11, rue Edmond Reuter,
L-5326 Contern, LUXEMBOURG

Office phone :  +352-2454-2566
Office fax:       +352-2454-3566
mobile phone:  +49 151 52 40 66 44

e-mail: alexei.boulbitch@iee.lu



[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web