Count
詳細とオプション
- Countの第1引数が頭部Listを持つ必要はない.
- Associationに用いられた場合,Countは要素の値のみを検定する.そのキーは検定しない.
- Countは,標準的なレベル指定を使用する.
-
n レベル 1 からレベル n まで Infinity レベル 1 からInfinityまで {n} レベル n のみ {n1,n2} レベル n1から n2まで - Countにおける levelspec のデフォルト値は{1}である.
- 正のレベル n は,n 個の指標によって指定された expr のすべての部分からなる.
- 負のレベル -n は,expr の深さ n のすべての部分からなる.
- レベル-1は,数,記号その他の下位区分を持たないオブジェクトからなる.
- レベル0は式全体に相当する.
- オプション設定がHeads->Trueのとき,Countは式の頭部とその部分を見る.
- Count[pattern][expr]はCount[expr,pattern]に等しい.
- Parallelize[Count[list,pattern]]はCount[list,pattern]をすべてのサブカーネルで並列に計算する. »
例題
すべて開く すべて閉じる例 (4)
Count[{a, b, a, a, b, c, b}, b]Association中のxのベキを数える:
Count[<|1 -> 1 + x ^ 2, 2 -> x ^ 4, 3 -> a + (1 + x ^ 2) ^ 2|>, x ^ _]Count[<|1 -> 1 + x ^ 2, 2 -> x ^ 4, 3 -> a + (1 + x ^ 2) ^ 2|>, x ^ _, Infinity]Count[<|1 -> 1 + x ^ 2, 2 -> x ^ 4, 3 -> a + (1 + x ^ 2) ^ 2|>, _Symbol, Infinity]スコープ (5)
Countはパターンと使うことができる:
Count[{a, 2, a, a, 1, c, b, 3, 3}, _Integer]Count[{a, b, a, a, b, c, b, a, a}, Except[b]]Count[{{a, a, b}, b, {a, b, a}}, b, 2]Count[{{a, a, b}, b, {a, b, a}}, b, {2}]Count[x ^ 3 + 1.5x ^ 2 + Pi x + 7, _ ? NumericQ, -1]Count[5, _ ? NumericQ, -1]要素が2つのリストを使って明示的にレベル0を含むようにする:
Count[5, _ ? NumericQ, {0, -1}]オプション (1)
アプリケーション (3)
特性と関係 (5)
Count[{1, "f", g, "h", "7"}, _ ? StringQ]Length[Cases[{1, "f", g, "h", "7"}, _ ? StringQ]]Count[{1, "f", g, "h", "7"}, _ ? StringQ]Length[Position[{1, "f", g, "h", "7"}, _ ? StringQ]]レベル{0}における数は,事実上,MatchQを数値化したものである:
MatchQ[5, _Integer]Count[5, _Integer, {0}] == 1ほとんどの式について,LeafCountは,レベル{-1}におけるBlank[]にマッチする数に等しい:
LeafCount[1 + a + b ^ 2]Count[1 + a + b ^ 2, _, {-1}, Heads -> True]Countは,RationalおよびComplexを原子として扱う:
AtomQ /@ {1 / 2, 1 + I}Count[{1 / 2, 1 + I}, _, {-1}, Heads -> True]LeafCountは,RationalおよびComplexの数を,それぞれのFullFormを使って数える:
{1 / 2, 1 + I}//FullFormLeafCount[{1 / 2, 1 + I}]Countを並列に計算する:
Parallelize[Count[Range[10 ^ 6], _ ? PrimeQ]]テクニカルノート
関連するガイド
-
▪
- リストへの数学的およびカウント操作 ▪
- パターンマッチング関数 ▪
- 離散データと整数データ ▪
- 構造化されたデータ集合の計算 ▪
- リスト操作 ▪
- リストの要素 ▪
- データの配列の操作 ▪
- 規則とパターン ▪
- 数値データ ▪
- 表形式の変換
履歴
1988 で導入 (1.0) | 2014 で更新 (10.0)
テキスト
Wolfram Research (1988), Count, Wolfram言語関数, https://reference.wolfram.com/language/ref/Count.html (2014年に更新).
CMS
Wolfram Language. 1988. "Count." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2014. https://reference.wolfram.com/language/ref/Count.html.
APA
Wolfram Language. (1988). Count. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Count.html
BibTeX
@misc{reference.wolfram_2026_count, author="Wolfram Research", title="{Count}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/Count.html}", note=[Accessed: 15-October-2026]}
BibLaTeX
@online{reference.wolfram_2026_count, organization={Wolfram Research}, title={Count}, year={2014}, url={https://reference.wolfram.com/language/ref/Count.html}, note=[Accessed: 15-October-2026]}