Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ListDimension function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg72571] Re: [mg72595] ListDimension function
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 11 Jan 2007 02:00:12 -0500 (EST)
  • References: <200701100907.EAA13288@smc.vnet.net>

On 10 Jan 2007, at 09:07, 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.
>

I think the following should work:

ListDimension[expr_]:=Depth[0*expr]-1

for example:

  ListDimension[a + b]
  0

  ListDimension[{1, 2, x*y}]
  1

  ListDimension[{{}, {{1, 2}}, a}]
  3


Andrzej Kozlowski

Oxford, UK.


  • Prev by Date: Problem with Position applied on 2D list?
  • Next by Date: Re: ListDimension function
  • Previous by thread: ListDimension function
  • Next by thread: Re: ListDimension function