ASN2
Let's Become Pythonic!
Deadline
Feb 14, 2022 at 11:59:59 PM (Individual Submissions).
What you need to do?
Intelligence in robots is generally performed in-terms of a computer program or code. One of the most common languages to program robots has been Python due to it's ease of use and learnability. In order to facilitate building autonomous robots, we'll first learn the basics of Python through a set of small yet fun tasks.
Step 0: Find Your Favorite IDE/Editor
Before you run your code to do something cool, you need a place to write your programs/code in. This is called an Editor or an Integrated Development Environment (IDE). There are a lot of amazing editors/IDEs around developed by the amazing community of developers. Each of these tools have their own great set of features and visual appeal. To a large extent the choice of the IDE/Editor also comes down to personal preference. Currently, most common choices for Python are
Sublime Text,
Atom,
PyCharm,
Visual Studio Code,
Jupyter Notebook. Other super popular editors that have a steep learning curve are
Emacs (I personally use this!) and
Vim (A lot of my graduate students use this). Now, that you have found your favorite editor, install it by following the instructions on their respective websites for your particular operating system. I would recommend using a dark theme so that programming is easy on your eyes for working long periods.
Step 1: Let's Learn Numpy
Your task it to implement the following using only
Numpy and built-in Python data-structures.
- Construct two random \(3 \times 3\) matrices \(A\) and \(B\). Now perform the following operations, (a) \(AB\) (matrix multiplication), (b) \(A \circ B\) (element-wise multiplication), (c) \(A^TBA^{-1}\), (d) Reshape \(A\) and \(B\) to \(9\times 1\) vectors \(A_v, B_v\) and concatenate \(A_v, B_v\) to make a \(9\times 2\) vector called \(C_v\). Now compute the \(l_2\) norm of \(C_v\) which will be of size \(9\times 1\).
- Create a random Image \(I\) of size \(256 \times 256\) whose element values range from \([0, 255]\). Create another random Mask \(M\) of size \(256 \times 256\) whose element values are either 0 or 1. Now replace the values in Image \(I\) at indexes corresponding to ones in mask \(M\) to 0.
Step 2: Let's Learn Python
- Why do you need __name__ == "__main__" in a Python script?
- Create a function that takes two numpy array square matrices \(A\) and \(B\) of any size and does the following: (a) Raise an exception with the message "Matrices need to be of same size!", (b) If matrices are of same size, return the value \(A^TBA^{-1}\). Test your function with random sample matrices \(A\) and \(B\) from the main function.
- Create a function that returns a value of -1 or +1 with equal probability. Test your function from the main function.
- How do you convert: (a) a list to a tuple?, (b) a list to a numpy array?, (c) a list to a dictionary?
- Create a random list of numbers of length 10 where each element varies from 0 to 10. Then use list comprehension to create a new list where any number between \([5,7]\) in the original is set to zero and other numbers remain the same. E.g., input list: \([0,1,1,2,3,4,5,7,9,0]\), output list: \([0,1,1,2,3,4,0,0,9,0]\).
- Create a random list of numbers of length 10 where each element varies from 0 to 10. Then use list comprehension to create a new list that has "Even" and "Odd" for each number (Assume 0 to be even). E.g., input list: \([0,1,1,2,3,4,5,7,9,0]\), output list: \([Even,Odd,Odd,Even,Odd,Even,Odd,Odd,Odd,Even]\).
- Create a random numpy array \(I\) of size \(256\times 256\) whose element values range from \([0, 255]\). Now create an array \(I_s\) which is of size \((256\times 256 \times 3\) where each of the third channel (python index 2) is a copy of the image \(I\).
What you need to submit?
A
.zip file that has a document (feel free to use Word or Google Docs or any other software for this) converted to PDF with the following answers and required codes as mentioned below:
- What IDE/Editor did you choose in step 0 and why? Attach a screenshot (a screenshot is not a photo from your phone) of your editor in the document.
- Code (as .py python files and inside the document as a screenshot or copy pasted text) and sample input and outputs (can be in the form of screenshots) for questions in Step 1.
- Code (as .py python files and inside the document as a screenshot or copy pasted text) and sample input and outputs (can be in the form of screenshots) for questions in Step 2.
- Challenges you faced in solving this assignment along with lessons learned.
- Positive or Negative feedback about this assignment if you have any.
IMPORTANT NOTE:
The submissions are made through ELMS with the name
ASN2_DirID.pdf. Here,
DirID is your directory ID, i.e., the first part of your terpmail email address. For e.g., if your terpmail email address is
ABCD@terpmail.umd.edu, then your
DirID is
ABCD. Keep your submissions professional, grammatically correct without spelling mistakes. Do not use slangs and chat shorthands on your submissions.
You'll get 25% grade penalty for not following the submission guidelines.