Computer Science, asked by BansriShah8319, 1 year ago

Write a python function matrixflip(m,d) that takes as input a two dimensional matrix m and a direction d, where d is either 'h' or 'v'. If d == 'h', the function should return the matrix flipped horizontally. If d == 'v', the function should retun the matrix flipped vertically. For any other value of d, the function should return munchanged. In all cases, the argument m should remain undisturbed by the function

Answers

Answered by Anonymous
0

1

down vote

I have found what may be the issue, when you assign a list to another list m = myl you are not creating a new copy of that list to play around with, so any changes to m will affect myl. By replacing that with tempm = m.copy() you get a new version of the list that can be bent to your will. The following should work nicely:

def matrixflip(m,d):

tempm = m.copy()

if d=='h':

for i in range(0,len(tempm),1):

tempm[i].reverse()

elif d=='v':

tempm.reverse()

return(tempm)

Hope this helps you ☺️☺️✌️✌️❤️❤️

Answered by abhisheak991
2

Answer:

for nptel assignment

Explanation:

def  matrixflip(l,d):

   m=l[:]

   def ver(m):

       count=1

       n=len(m)

       for a in range(n-1):

           m[a],m[n-count]=m[n-count],m[a]

           count=count+1

       return(m)

   if d=='h':

       n=len(m)

       for a in range(n):

           m[a]=m[a][::-1]

       return(m)

       

   elif d=='v':

       return(ver(m))

   else:

       return(m)

Similar questions