-1

In my class, we are learning how to use Python to code robot poses. Specifically, creating a rotation matrix and translation matrix with numpy to represent these relative poses.

The one thing I don't understand is how our lab assistant demonstrated how to create the rotation matrix. I was able to create it a similar way on my own but I'd like to understand what he did. Here is the example he provided:

Rot = lambda theta: [[np.cos(theta), -np.sin(theta)],
                     [np.sin(theta), np.cos(theta)]]

R = Rot(np.pi/3)
R

Can someone explain what is the Rot = lambda theta: code means? When I did it on my own I just created a variable theta and the equation for Rot with the variable theta inside of it in the appropriate places. I do not understand what this lambda means.

1 Answers1

3

It's the equivalent of this:

def Rot(theta):
    return [[np.cos(theta), -np.sin(theta)],
            [np.sin(theta), np.cos(theta)]]

The code lambda param1, param2: return_value creates a function with param1 and param2 as parameters, the code after the colon (:) is automatically run and returned when you call the function. Rot = is simply assigning the resulting lambda function to the Rot variable, and since all functions are actually variables, that works.