Re: how to check for NumericQ arbitrary data structure
- To: mathgroup at smc.vnet.net
- Subject: [mg126220] Re: how to check for NumericQ arbitrary data structure
- From: Christoph Lhotka <christoph.lhotka at fundp.ac.be>
- Date: Thu, 26 Apr 2012 05:24:46 -0400 (EDT)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201204201144.HAA21808@smc.vnet.net> <201204210431.AAA29236@smc.vnet.net> <201204240932.FAA24447@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 > >
- References:
- Find all roots with FindRoot
- From: Sam Takoy <sam.takoy@yahoo.com>
- Re: Find all roots with FindRoot
- From: "Harvey P. Dale" <hpd1@nyu.edu>
- how to check for NumericQ arbitrary data structure
- From: Ted Sariyski <tsariysk@craft-tech.com>
- Find all roots with FindRoot