RE: ListDimension function
- To: mathgroup at smc.vnet.net
- Subject: [mg72592] RE: [mg72595] ListDimension function
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 11 Jan 2007 03:24:41 -0500 (EST)
Carlos, Will the following work? test1 = a + b; test2 = {1, 2, x*y}; test3 = {1, 2, {3, 0, 1}}; test4 = {{}, {}, {}}; test5 = {{}, {{1, 2}}, a}; ListDimension[expr_] := Max[Length /@ Position[{expr}, {___}]] ListDimension /@ {test1, test2, test3, test4, test5} {0, 1, 2, 2, 3} David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: carlos at colorado.edu [mailto:carlos at colorado.edu] Hi - I need a short function ListDimension that given a list returns its "brace dimensionality" = max number of brace levels to reach deepest entry. Examples List ListDimension a+b 0 {1,2,x*y} 1 {1,2,{3,0,1}} 2 {{},{},{}} 2 {{},{{1,2}},a} 3 Built-in functions dont seem to be of help. Dimensions is restricted to matrix or tensor type of lists. Depth (minus 1) doesnt help as it is entry type dependent: Depth[{1,2,3}] -> 2 Depth[{1,2,3+a}] -> 3 Depth[{1,2,3+a+Sqrt[x+y]}] -> 5 For the above three, ListDimension=1.