Re: ListDimension function
- To: mathgroup at smc.vnet.net
- Subject: [mg72575] Re: [mg72595] ListDimension function
- From: János <janos.lobb at yale.edu>
- Date: Thu, 11 Jan 2007 02:16:18 -0500 (EST)
- References: <200701100907.EAA13288@smc.vnet.net>
On Jan 10, 2007, at 4:07 AM, carlos at colorado.edu wrote: > 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. Here is a newbie approach. If your list is lst, then: In[2]:= Max[Length /@ Position[lst, List]] Out[2]= 3 will work. For a+b it gives minus Infinity if you can live with that. János
- References:
- ListDimension function
- From: carlos@colorado.edu
- ListDimension function