Mathematica 9 is now available

Count

Usage

Count[list, pattern]给出了list中匹配pattern的元素个数。
Count[expr, pattern, levelspec] 给出了匹配pattern的子表达式的总个数,这些子表达式出现在expr中由levelspec指定的级别上。


Notes

• 级别规定描述在A.3.6节.
• 参见Mathematica全书: 1.8.5节 and 2.3.2节.
•同时参见: FreeQ, MemberQ, Cases, Select, Position.
Further Examples

(See the Further Examples for FullSimplify for a demonstration of how Count can be used to affect the outcome of a simplification.)

This counts the number of occurrences of Real numbers in the list. (An Integer is not considered to be Real, any more than a Real is considered to be Complex.)

In[1]:=  

Out[1]=

This command returns the number of summands that are powers. (Note that the first argument to Count need not be a list.)

In[2]:=  

Out[2]=

This returns the number of expressions that occur in the sum at any level and are powers. This count is higher; the actual matches can be seen by replacing Count with Cases.

In[3]:=  

Out[3]=



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.