This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / signal / _arraytools / const_ext

function

scipy.signal._arraytools:const_ext

source: build-install/usr/lib/python3.14/site-packages/scipy/signal/_arraytools.py:160

Signature

def const_ext(x, n, axis = -1)

Summary

Constant extension at the boundaries of an array

Extended Summary

Generate a new ndarray that is a constant extension of x along an axis.

The extension repeats the values at the first and last element of the axis.

Parameters

x : ndarray

The array to be extended.

n : int

The number of elements by which to extend x at each end of the axis.

axis : int, optional

The axis along which to extend x. Default is -1.

Examples

import numpy as np
from scipy.signal._arraytools import const_ext
a = np.array([[1, 2, 3, 4, 5], [0, 1, 4, 9, 16]])
const_ext(a, 2)
✓
array([[ 1,  1,  1,  2,  3,  4,  5,  5,  5],
       [ 0,  0,  0,  1,  4,  9, 16, 16, 16]])
Constant extension continues with the same values as the endpoints of the array:
t = np.linspace(0, 1.5, 100)
a = 0.9 * np.sin(2 * np.pi * t**2)
b = const_ext(a, 40)
import matplotlib.pyplot as plt
✓
plt.plot(np.arange(-40, 140), b, 'b', lw=1, label='constant extension')
plt.plot(np.arange(100), a, 'r', lw=2, label='original')
plt.legend(loc='best')
✗
<matplotlib.legend.Legend object at 0x7f3f43a19e80>
plt.show()
✓
fig-814872654feede90.png

Aliases

  • scipy.signal._arraytools.const_ext