Skip to content

Instantly share code, notes, and snippets.

@valpackett
Created December 17, 2017 12:54
Show Gist options
  • Save valpackett/5382d36c12bfe4516594e1084ace5e5a to your computer and use it in GitHub Desktop.
Save valpackett/5382d36c12bfe4516594e1084ace5e5a to your computer and use it in GitHub Desktop.
def pad_or_trim(mat, required_len):
if mat.shape[0] < required_len:
return np.pad(mat, ((0, required_len - mat.shape[0]), (0, 0)), 'constant')
if mat.shape[0] > required_len:
return mat[:required_len]
return mat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment