本文簡要介紹 python 語言中 scipy.cluster.vq.vq
的用法。
用法:
scipy.cluster.vq.vq(obs, code_book, check_finite=True)#
將代碼簿中的代碼分配給觀察。
將代碼簿中的代碼分配給每個觀察值。 'M' by'N' obs 數組中的每個觀察向量與代碼簿中的質心進行比較,並分配最接近質心的代碼。
obs 中的特征應該有單位方差,這可以通過將它們傳遞給 whiten 函數來實現。可以使用k-means 算法或不同的編碼算法創建代碼簿。
- obs: ndarray
‘M’ x ‘N’ 數組的每一行都是一個觀察值。這些列是每次觀察期間看到的“features”。必須首先使用 whiten 函數或等效函數對特征進行白化。
- code_book: ndarray
密碼本通常使用k-means 算法生成。數組的每一行包含一個不同的代碼,列是代碼的特征。
>>> # f0 f1 f2 f3 >>> code_book = [ ... [ 1., 2., 3., 4.], #c0 ... [ 1., 2., 3., 4.], #c1 ... [ 1., 2., 3., 4.]] #c2
- check_finite: 布爾型,可選
是否檢查輸入矩陣是否僅包含有限數。禁用可能會提高性能,但如果輸入確實包含無窮大或 NaN,則可能會導致問題(崩潰、非終止)。默認值:真
- code: ndarray
一個長度為 M 的數組,保存每個觀察的代碼簿索引。
- dist: ndarray
觀測值與其最近代碼之間的失真(距離)。
參數 ::
返回 ::
例子:
>>> import numpy as np >>> from scipy.cluster.vq import vq >>> code_book = np.array([[1., 1., 1.], ... [2., 2., 2.]]) >>> features = np.array([[1.9, 2.3, 1.7], ... [1.5, 2.5, 2.2], ... [0.8, 0.6, 1.7]]) >>> vq(features, code_book) (array([1, 1, 0], dtype=int32), array([0.43588989, 0.73484692, 0.83066239]))
相關用法
- Python SciPy vq.whiten用法及代碼示例
- Python SciPy vq.kmeans用法及代碼示例
- Python SciPy vq.kmeans2用法及代碼示例
- Python SciPy interpolate.make_interp_spline用法及代碼示例
- Python SciPy stats.anderson用法及代碼示例
- Python SciPy ClusterNode.pre_order用法及代碼示例
- Python SciPy stats.iqr用法及代碼示例
- Python SciPy FortranFile.read_record用法及代碼示例
- Python SciPy ndimage.correlate用法及代碼示例
- Python SciPy special.exp1用法及代碼示例
- Python SciPy special.expn用法及代碼示例
- Python SciPy signal.czt_points用法及代碼示例
- Python SciPy interpolate.krogh_interpolate用法及代碼示例
- Python SciPy ndimage.morphological_gradient用法及代碼示例
- Python SciPy distance.sokalmichener用法及代碼示例
- Python SciPy linalg.eigvalsh_tridiagonal用法及代碼示例
- Python SciPy linalg.cdf2rdf用法及代碼示例
- Python SciPy csc_array.diagonal用法及代碼示例
- Python SciPy fft.idctn用法及代碼示例
- Python SciPy linalg.LaplacianNd用法及代碼示例
- Python SciPy linalg.solve_circulant用法及代碼示例
- Python SciPy hierarchy.ward用法及代碼示例
- Python SciPy signal.chirp用法及代碼示例
- Python SciPy stats.genpareto用法及代碼示例
- Python SciPy ndimage.variance用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.cluster.vq.vq。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。