Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

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

Search the Archive

Re: count the number of sub-list in a list

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122241] Re: count the number of sub-list in a list
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sat, 22 Oct 2011 06:06:10 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 10/21/11 at 7:28 AM, hitphyopt at gmail.com (Gy Peng) wrote:

>I have a list like:

<array snipped>

>I consider each of {{*, *, *}, {*, *, *}, {*,*,*}} is one single
>element, so how could I count how many element in the whole list?
>Thank you very much!

Using data to be your array

In[17]:= Times @@ Drop[Dimensions[data], -2]

Out[17]= 16

Here, I use the fact the element you want to count is a n x m
array. So, the last two values in the list returned by
Dimensions will be the dimensions of the element. Dropping the
last two values gives the dimensions of an array of n x m
elements. So, the product is the number of those m x n elements.

Equivalently, you could compute the total number of entries at
the lowest level then divide by the number of entries in you
element, i.e.,

In[18]:= Times @@ Dimensions[data]/9

Out[18]= 16




  • Prev by Date: Defining a variable from an error message (NDSolve::ndsz)
  • Next by Date: Re: Simplifying radicals
  • Previous by thread: Re: count the number of sub-list in a list
  • Next by thread: Re: count the number of sub-list in a list