Skip to content

Instantly share code, notes, and snippets.

@kwinkunks
Created May 26, 2020 10:43
Show Gist options
  • Save kwinkunks/06e728b2331c7d0e792b7eec74abf517 to your computer and use it in GitHub Desktop.
Save kwinkunks/06e728b2331c7d0e792b7eec74abf517 to your computer and use it in GitHub Desktop.
RMS of a cube
import numpy as np
from scipy.ndimage import generic_filter
def rms_1d(trace_segment):
"""
This function runs on every piece of `size` defined in the
generic_filter, below. It returns a single value.
"""
return np.sqrt(np.sum(trace_segment**2)/trace_segment.size)
arr = np.random.random((10, 10, 20)) - 0.5
generic_filter(arr,
rms_1d,
size=(1, 1, 3), # Size gives shape of input to function.
mode='nearest' # How to handle edges.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment