scipy.ndimage.

correlate1d#

scipy.ndimage.correlate1d(input, weights, axis=-1, output=None, mode='reflect', cval=0.0, origin=0)[source]#

沿給定軸計算 1 維相關性。

沿給定軸的陣列線與給定的權重相關。

參數:
inputarray_like

輸入陣列。

weightsarray

數字的 1 維序列。

axisint, optional

要沿其計算的 input 軸。預設值為 -1。

outputarray 或 dtype, optional

放置輸出的陣列,或傳回陣列的 dtype。預設會建立與輸入相同 dtype 的陣列。

mode{‘reflect’, ‘constant’, ‘nearest’, ‘mirror’, ‘wrap’}, optional

mode 參數決定輸入陣列如何超出其邊界延伸。預設值為 ‘reflect’。每個有效值的行為如下

‘reflect’ (d c b a | a b c d | d c b a)

輸入會藉由反射最後一個像素的邊緣來延伸。此模式有時也稱為半樣本對稱。

‘constant’ (k k k k | a b c d | k k k k)

輸入會藉由以相同的常數值填滿邊緣以外的所有值來延伸,常數值由 cval 參數定義。

‘nearest’ (a a a a | a b c d | d d d d)

輸入會藉由複製最後一個像素來延伸。

‘mirror’ (d c b | a b c d | c b a)

輸入會藉由反射最後一個像素的中心來延伸。此模式有時也稱為全樣本對稱。

‘wrap’ (a b c d | a b c d | a b c d)

輸入會藉由環繞到相對邊緣來延伸。

為了與內插函數保持一致性,也可以使用以下模式名稱

‘grid-mirror’

這是 ‘reflect’ 的同義詞。

‘grid-constant’

這是 ‘constant’ 的同義詞。

‘grid-wrap’

這是 ‘wrap’ 的同義詞。

cvalscalar, optional

如果 mode 為 ‘constant’,則填滿輸入邊緣以外的值。預設值為 0.0。

originint, optional

控制濾波器在輸入陣列像素上的放置位置。值 0 (預設值) 將濾波器置於像素中心,正值將濾波器向左移動,負值向右移動。

傳回值:
resultndarray

相關性結果。具有與 input 相同的形狀。

範例

>>> from scipy.ndimage import correlate1d
>>> correlate1d([2, 8, 0, 4, 1, 9, 9, 0], weights=[1, 3])
array([ 8, 26,  8, 12,  7, 28, 36,  9])