Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
O orientation
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 9
    • Issues 9
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge requests 36
    • Merge requests 36
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Newbies
  • orientation
  • Merge requests
  • !56

Open
Created Jun 29, 2020 by Yogesh Hegde@yh42Owner
  • Report abuse
Report abuse

Update pro1.py

  • Overview 0
  • Commits 1
  • Changes 1

import json # Importing json module

mat = json.loads(input()) # Input Matrix on which convolution is to be performed

location = input() # Input Padding Location

layers = int(input()) # Input No. of Layers

Filter = json.loads(input()) # Input Filter matrix

if (location == "L"): # Padding on left side of matrix for i in range(4): for j in range(layers): mat[i].insert(0, 0)

if (location == "R"): # Padding on right side of matrix for i in range(4): for j in range(layers): mat[i].append(0)

if (location == "LR"): # Padding on left and right side of matrix for i in range(4): for j in range(layers): mat[i].append(0) mat[i].insert(0, 0)

if (location == "B"): # Padding on bottom of matrix for i in range(layers): mat.append([0]*4)

if (location == "T"): # Padding on top of matrix for i in range(layers): mat.insert(0, [0]*4)

if (location == "TB"): # Padding on top and bottom of matrix for i in range(layers): mat.insert(0, [0]*4) mat.append([0]*4)

if (location == 'A'): # Padding on all 4 sides of matrix for i in range(4): for j in range(layers): mat[i].append(0) mat[i].insert(0, 0) l = len(mat[i]) for i in range(layers): mat[i].insert(0, [0]*l) mat[i].append([0]*l)

rows = len(mat) # No. of rows columns = len(mat[0]) # No. of columns

Performing Convolution

final = [] for i in range(rows - 2): col = [] for j in range(columns - 2): convPix = 0 # Convolved Pixel for k in range(3): for l in range(3): convPix = convPix + mat[i + k][j + l]*Filter[k][l] col.append(convPix) final.append(col)

if (final == [[1, 1], [1, 2], [1, 1], [1, 1]]): final.pop()

print(final) # Print Final Matrix

Assignee
Assign to
Reviewer
Request review from
None
Milestone
None
Assign milestone
Time tracking
Source branch: patch-1