Skip to content

Instantly share code, notes, and snippets.

@kocur4d
Created April 28, 2018 12:47
Show Gist options
  • Save kocur4d/8fdbda894a9e71d0757f4d4714794c9c to your computer and use it in GitHub Desktop.
Save kocur4d/8fdbda894a9e71d0757f4d4714794c9c to your computer and use it in GitHub Desktop.
Padding np.array with constant data
data = np.array([1,2,3,4,5])
np.pad(data, (2, 3), 'constant', constant_values=9)
# [9,9,1,2,3,4,5,9,9,9]
np.pad(data, (0, 3), 'constant', constant_values=9)
# [1,2,3,4,5,9,9,9]
np.pad(data, (2, 0), 'constant', constant_values=9)
# [9,9,1,2,3,4,5]
np.pad(data, (2, 3), 'constant', constant_values=(8,9))
# [8,8,1,2,3,4,5,9,9,9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment