Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-036

2D Shear Matrix Apply

Problem

Apply a horizontal shear with factor k to a 2D vector v.

x' = x + k*y and y' = y. The shear matrix is [[1, k], [0, 1]].

Hint

Only the x coordinate changes; it shifts in proportion to y.

Test cases

case 1
in: [[1,1],2]
expected: [3,1]
case 2
in: [[0,5],3]
expected: [15,5]
case 3
in: [[2,3],0]
expected: [2,3]
case 4
in: [[1,2],-1]
expected: [-1,2]
Starter codePython
def shear_2d(v, k):
    # Your code here
    pass

4 test cases · run your code against them in the editor