Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Interrogating lists of unequal lenghths

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67383] Re: Interrogating lists of unequal lenghths
  • From: Bill Rowe <readnewsciv at earthlink.net>
  • Date: Wed, 21 Jun 2006 02:12:52 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On 6/20/06 at 2:15 AM, kevinbowman at mac.com (kevin_jazz) wrote:

>I'm trying to understand how to assess the dimensions of a list
>containing elements of unequal length. Let's say I have the list

>U If, on the other hand, I set up the following list

>In[5]:= x={{1},{2,3},{4,5,6,7}}

>In[6]:= Dimensions[x]

>Out[6]= {3}

>The Dimensions command tells me I have only 3 elements.  But, I need
>some way to figure out that the first sublist has length 1, second
>has length 2, and the third has length 4 in some automated fashion.
>I've looked through the other commands like Depth and Length but I
>don't see anything that does this.

It seems to me there are two reasonably simple possibilities. You might do

In[2]:=
{Depth@#-1,Length@#}&/@x

Out[2]=
{{1, 1}, {1, 2}, {1, 4}}

which returns a result similar to dimensions, That is the first number specifies the number of rows in the element and the second the number of columns for the element (number of sub-elements). By using Depth you will be notified is one of the elements in x isn't a vector.

But if you are certain each element of x will be a vector than simply doing

In[3]:=
Length/@x

Out[3]=
{1,2,4}

should suffice
--
To reply via email subtract one hundred and four


  • Prev by Date: Re: Interrogating lists of unequal lenghths
  • Next by Date: Re: Help: ratio of integral of f(x)^2 to square of integral of f(x)
  • Previous by thread: Re: Interrogating lists of unequal lenghths
  • Next by thread: Re: Interrogating lists of unequal lenghths