C1W3_Assignment - Exercise 2

Guys,

Does anyone could help me or give me a tip about the folowiing code?
I am having dificult to create a 𝑇((π‘₯,𝑦))=(π‘₯+π‘šπ‘¦,𝑦).

GRADED FUNCTION: T_hshear

def T_hshear(m, v):
β€œβ€"
Performs a 2D horizontal shearing transformation on an array v using a shearing factor m.

Args:
    m (float): The shearing factor.
    v (np.array): The array to be sheared.

Returns:
    np.array: The sheared array.
"""

### START CODE HERE ###
# Define the transformation matrix
T = np.array([[None,None], [None,None]])
# 𝑇((π‘₯,𝑦))=(π‘₯+π‘šπ‘¦,𝑦)

# Compute the transformation
w = None @ None

### END CODE HERE ###

return w

Hey there @renan_leme

To create the horizontal shearing transformation T((x,y)) = (x + my, y) , you need to define the transformation matrix T and apply it to the input vector v . The transformation matrix for this shearing operation is:

T = \begin{bmatrix} 1 & m \\ 0 & 1 \end{bmatrix}

Hope it helps! Feel free to ask if you need further assistance.

Thanks @Alireza_Saei. You always save me!

You’re welcome! Glad I could help! :raised_hands:

thank you so much for this post, I had been confused for a while !
I’m still a bit confused though, how are we translating the equation onto the matrix?

Just β€œplay out” the matrix multiplication T \cdot v where v is the column vector with elements [[x], [y]].

Hi there - I am doing this course on Coursera and it seems like the test for this function is trying to test two different values for m simultaneously. I can pass one of the tests when I add that m value but then I fail the other one. Is there a way to set up the function so that it has multiple m values?

The m value is a parameter passed to your function, right? There is no need to β€œhard-code” it to any specific value: just use the value that is passed to you. That is the point of having functions take parameters: you can write general code that works for any input value.

Thank you for your help here!