Skip to content

Instantly share code, notes, and snippets.

@anirudhshenoy
Last active December 13, 2019 10:07
Show Gist options
  • Select an option

  • Save anirudhshenoy/d4e4228ebb884066efd65299f1d169cb to your computer and use it in GitHub Desktop.

Select an option

Save anirudhshenoy/d4e4228ebb884066efd65299f1d169cb to your computer and use it in GitHub Desktop.
Naive Implementation of Im2Col
def im2col(x, kernel):
kernel_shape = kernel.shape[0]
rows = []
# Assuming Padding = 0, stride = 1
for row in range(x.shape[0] - 1):
for col in range(x.shape[1] - 1):
window = x[row: row + kernel_shape, col: col + kernel_shape]
rows.append(window.flatten())
return np.transpose(np.array(rows))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment