Created
April 21, 2022 09:59
-
-
Save Mynuddin-dev/bba02e846f7844085a55e8cdfb229251 to your computer and use it in GitHub Desktop.
Convolution output matrix for stride 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
input_matrix=np.array([[3,0,1,2,7,4], | |
[1,5,8,9,3,1], | |
[2,7,2,5,1,3], | |
[0,1,3,1,7,8], | |
[4,2,1,6,2,8], | |
[2,4,5,2,3,9] | |
]) | |
filter_matrix = np.array([[1,0,-1], | |
[1,0,-1], | |
[1,0,-1] | |
]) | |
input_size = len(input_matrix) | |
filter_size = len(filter_matrix) | |
stride=1 | |
padding =0 | |
output_size = int((input_size+(2*padding)-filter_size)/stride)+1 | |
print(output_size) | |
Output_matrix = np.zeros((output_size,output_size)) | |
Output_matrix | |
for i in range(len(input_matrix)-2): | |
for j in range(len(input_matrix)-2): | |
x = input_matrix[i:filter_size+i , j:filter_size+j] | |
y=x.ravel()*filter_matrix.ravel() | |
Output_matrix[i][j]=y.sum() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment