gauss1d#

gauss1d(x=None, y=None, xi=None, scale=None, use32=True)[source]#

Gaussian 1D smoothing kernel.

Create smooth interpolation of input points at interpolated points. If no points are supplied, use the same as the input points.

Parameters:
  • x (arr) – 1D list of x coordinates

  • y (arr) – 1D list of y values at each of the x coordinates

  • xi (arr) – 1D list of points to calculate the interpolated y

  • scale (float) – how much smoothing to apply (by default, width of 5 data points)

  • use32 (bool) – convert arrays to 32-bit floats (doubles speed for large arrays)

Examples:

# Setup
import numpy as np
import matplotlib.pyplot as plt
import sciris as sc

x = np.random.rand(40)
y = (x-0.3)**2 + 0.2*np.random.rand(40)

# Smooth
yi = sc.gauss1d(x, y)
yi2 = sc.gauss1d(x, y, scale=0.3)
xi3 = np.linspace(0,1)
yi3 = sc.gauss1d(x, y, xi)

# Plot original and interpolated versions
plt.scatter(x, y,     label='Original')
plt.scatter(x, yi,    label='Default smoothing')
plt.scatter(x, yi2,   label='More smoothing')
plt.scatter(xi3, yi3, label='Uniform spacing')
plt.show()

# Simple usage
sc.gauss1d(y)

New in version 1.3.0.