Re: Interrogating lists of unequal lenghths
- To: mathgroup at smc.vnet.net
- Subject: [mg67394] Re: [mg67367] Interrogating lists of unequal lenghths
- From: gardyloo <gardyloo at mail.wsu.edu>
- Date: Wed, 21 Jun 2006 02:13:23 -0400 (EDT)
- References: <200606200615.CAA15916@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Hi, Kevin,
If your list contains only one "sublevel" of lists (as in your
example), try mapping Length over the list. Something like
In[1]:=
y = {{1, 2}, {3, 4}, {5, 6}}
Out[1]=
{{1, 2}, {3, 4}, {5, 6}}
In[2]:=
Length /@ y
Out[2]=
{2, 2, 2}
x = {{1}, {2, 3}, {4, 5, 6, 7}}
Length /@ x
Out[3]=
{{1}, {2, 3}, {4, 5, 6, 7}}
Out[4]=
{1, 2, 4}
Hope that helps!
C.O.
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 with elements of equal sizes
>
> In[12]:=
> y={{1,2},{3,4},{5,6}}
>
> Out[12]=
> {{1,2},{3,4},{5,6}}
>
> In[13]:=
> Dimensions[y]
>
> Out[13]=
> {3,2}
>
> Using the Dimensions function I can determine the size of the resulting
> array. 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.
>
> What's the right to do it?
>
> Thanks,
>
> Kevin
>
>
>
--
==========================================================
Curtis Osterhoudt
gardyloo at mail.remove_this.wsu.and_this.edu
PGP Key ID: 0x088E6D7A
Please avoid sending me Word or PowerPoint attachments
See http://www.gnu.org/philosophy/no-word-attachments.html
==========================================================
--------------020009080209040305020807
name="gardyloo.vcf"
filename="gardyloo.vcf"
begin:vcard
fn:Curtis Osterhoudt
n:Osterhoudt;Curtis
email;internet:gardyloo at mail.remove_this.wsu.and_this.edu
tel;work:509.335.4946
x-mozilla-html:FALSE
version:2.1
end:vcard
--------------020009080209040305020807--
- References:
- Interrogating lists of unequal lenghths
- From: "kevin_jazz" <kevinbowman@mac.com>
- Interrogating lists of unequal lenghths