Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
2024.1.0 - 日本語


sample

置換を有する標本化

呼び出し手順

s = sample(n, X, orient)

パラメータ

n

正の整数 (標本の大きさ)

X

任意のデータ型の配列、またはセル配列. この配列からサンプルが抽出されます.

orient

The shape of samples:

  • '*' (default): elements of X are sampled.
  • 1 or 'r': rows of X are sampled.
  • 2 or 'c': rolumns of X are sampled.

s

同じタイプのサンプルを含むベクトル、行列、またはセル配列 X として.

説明

s = sample(n, X) (or s = sample(n, X, '*')) returns a vector s of n elements randomly chosen among X elements, with replacement.

s = sample(n, X, 'r') (or s = sample(n, X, 1)) returns a matrix of size n x size(X,'c') of randomly chosen Rows of X, with replacement.

s = sample(n, X, 'c') (or s = sample(n, X, 2)) returns a matrix of size size(X,'r') x n of randomly chosen Columns of X, with replacement.

Sampling some numbers:

data = (1:9)' * 10.^(-3:3)
sample(8, data)
sample(5, data, "r")
sample(5, data, "c")
--> data = (1:9)' * 10.^(-3:3)
 data  =
   0.001   0.01   0.1   1.   10.   100.   1000.
   0.002   0.02   0.2   2.   20.   200.   2000.
   0.003   0.03   0.3   3.   30.   300.   3000.
   0.004   0.04   0.4   4.   40.   400.   4000.
   0.005   0.05   0.5   5.   50.   500.   5000.
   0.006   0.06   0.6   6.   60.   600.   6000.
   0.007   0.07   0.7   7.   70.   700.   7000.
   0.008   0.08   0.8   8.   80.   800.   8000.
   0.009   0.09   0.9   9.   90.   900.   9000.

--> sample(8, data)
 ans  =
   0.02   0.06   10.   0.009   0.007   70.   6000.   60.

--> sample(5, data, "r")
 ans  =
   0.002   0.02   0.2   2.   20.   200.   2000.
   0.009   0.09   0.9   9.   90.   900.   9000.
   0.005   0.05   0.5   5.   50.   500.   5000.
   0.002   0.02   0.2   2.   20.   200.   2000.
   0.004   0.04   0.4   4.   40.   400.   4000.

--> sample(5, data, "c")
 ans  =
   10.   0.1   100.   0.1   0.001
   20.   0.2   200.   0.2   0.002
   30.   0.3   300.   0.3   0.003
   40.   0.4   400.   0.4   0.004
   50.   0.5   500.   0.5   0.005
   60.   0.6   600.   0.6   0.006
   70.   0.7   700.   0.7   0.007
   80.   0.8   800.   0.8   0.008
   90.   0.9   900.   0.9   0.009

Sampling some texts:

data = [
  "a"  "aa"  "aaa"  "aaaa"  "aaaaa"  "aaaaaa"
  "b"  "bb"  "bbb"  "bbbb"  "bbbbb"  "bbbbbb"
  "c"  "cc"  "ccc"  "cccc"  "ccccc"  "cccccc"
  "d"  "dd"  "ddd"  "dddd"  "ddddd"  "dddddd"
  "e"  "ee"  "eee"  "eeee"  "eeeee"  "eeeeee"
  "f"  "ff"  "fff"  "ffff"  "fffff"  "ffffff" ];

sample(5, data)
sample(4, data, "r")
sample(4, data, "c")
--> sample(5, data)
 ans  =
  "ffff"  "bb"  "aaaa"  "d"  "c"

--> sample(4, data, "r")
 ans  =
  "d"  "dd"  "ddd"  "dddd"  "ddddd"  "dddddd"
  "f"  "ff"  "fff"  "ffff"  "fffff"  "ffffff"
  "d"  "dd"  "ddd"  "dddd"  "ddddd"  "dddddd"
  "b"  "bb"  "bbb"  "bbbb"  "bbbbb"  "bbbbbb"

--> sample(4, data, "c")
 ans  =
  "aaaaaa"  "a"  "aaa"  "a"
  "bbbbbb"  "b"  "bbb"  "b"
  "cccccc"  "c"  "ccc"  "c"
  "dddddd"  "d"  "ddd"  "d"
  "eeeeee"  "e"  "eee"  "e"
  "ffffff"  "f"  "fff"  "f"

Sampling some cells:

data = {%f, %pi, "abc", 1-%z ; 1+%z, "ABC", %e, %f}
sample(5, data)
sample(3, data, "r")
sample(3, data, "c")
--> data = {%f, %pi, "abc", 1-%z ; 1+%z, "ABC", %e, %f}
 data  =
  [1x1 boolean   ]  [1x1 constant]  [1x1 string  ]  [1x1 polynomial]
  [1x1 polynomial]  [1x1 string  ]  [1x1 constant]  [1x1 boolean   ]

--> sample(5, data)
 ans  =
  [1x1 constant]  [1x1 polynomial]  [1x1 string]  [1x1 string]  [1x1 boolean]

--> sample(3, data, "r")
 ans  =
  [1x1 boolean   ]  [1x1 constant]  [1x1 string  ]  [1x1 polynomial]
  [1x1 polynomial]  [1x1 string  ]  [1x1 constant]  [1x1 boolean   ]
  [1x1 polynomial]  [1x1 string  ]  [1x1 constant]  [1x1 boolean   ]

--> sample(3, data, "c")
 ans  =
  [1x1 polynomial]  [1x1 boolean   ]  [1x1 string  ]
  [1x1 boolean   ]  [1x1 polynomial]  [1x1 constant]

参照

  • samplef — 母集団からの置換を有する標本化および その値の頻度.
  • samwr — 置換を行わない標本化
Report an issue
<< rand random samplef >>

Copyright (c) 2022-2024 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Mon Jun 17 17:54:17 CEST 2024