Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
286 changes: 286 additions & 0 deletions .ipynb_checkpoints/Homework-0-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,286 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Homework 0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The goal of this homework is to practice the skills learned in Lecture 2. These skills will be essential for the rest of this course."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before starting to work on this homework, **make a new folder** named ```hw0-submission``` in your private repo and download ```Homework-0.ipynb``` to that folder."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's make sure that you placed everything in the correct folder"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"You did everything correctly. Congrats!\n"
]
}
],
"source": [
"import os\n",
"error = False\n",
"\n",
"if os.path.basename(os.path.realpath('.')) != \"hw0-submission\":\n",
" print \"The name of the current directory should be 'hw0-submission'\"\n",
" error = True\n",
"\n",
"if not error:\n",
" print \"You did everything correctly. Congrats!\"\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, assuming that everything is in their correct place, you should ``git add`` all the new directories/files and make your initial ```git commit```."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## This is a Markdown cell"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Insert and edit your own markdown cell *below*. Write your favorite quote"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello world\n"
]
}
],
"source": [
"# This is a code cell. Try executing it.\n",
"print \"hello world\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write a function that takes as argument a string and returns its 3-letter suffix. If the string is shorter than 3 letters, return the whole string."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def suffix_3(string):\n",
" \"\"\"\n",
" Returns the 3-letter suffix.\n",
" \n",
" Parameters:\n",
" string: str\n",
" \n",
" Returns:\n",
" suffix: str\n",
" If `string` is more than 3-letters long, `suffix` is its 3-letter suffix. Otherwise, `suffix` is the same as `string`.\n",
" \"\"\"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"print suffix_3(\"Hi!\")\n",
"print suffix_3(\"Superb\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When you finish with the above function, don't forget to ```add``` and ```commit``` to your local git repository."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's print the versions of some packages that we will be using in the future. If any of these packages are not present, ```conda install``` them."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy\n",
"print 'numpy:', numpy.__version__\n",
"\n",
"import scipy\n",
"print 'scipy:', scipy.__version__\n",
"\n",
"import matplotlib\n",
"print 'matplotlib:', matplotlib.__version__\n",
"\n",
"import sklearn\n",
"print 'scikit-learn:', sklearn.__version__\n",
"\n",
"import pandas\n",
"print 'pandas:', pandas.__version__"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write a function that takes as argument a 2D list representing a matrix **M** and returns a boolean indicating whether **M** is an orthogonal matrix."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy\n",
"\n",
"def is_matrix_orthogonal(M):\n",
" \"\"\"\n",
" Returns whether M is an orthogonal matrix.\n",
" \n",
" Parameters:\n",
" M: 2D list\n",
" \n",
" Returns:\n",
" is_orthogonal: boolean\n",
" \"\"\"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false,
"scrolled": false
},
"outputs": [],
"source": [
"print is_matrix_orthogonal([[1, 0], [0, -1]])\n",
"print is_matrix_orthogonal([[-1.2396, -4.3801, -1.7737], [-1.3121, -2.9193, -4.5496], [-2.1143, 0.0363, 0.2022]])\n",
"print is_matrix_orthogonal([[-0.8185, 0.5740, -0.0249], [-0.2510, -0.3183, 0.9142], [-0.5168, -0.7544, -0.4046]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When you finish with the above function, don't forget to ```add``` and ```commit``` to your local git repository."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Submitting"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, you can push your changes to Github."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Code for setting the style of the notebook\n",
"from IPython.core.display import HTML\n",
"def css_styling():\n",
" styles = open(\"../../theme/custom.css\", \"r\").read()\n",
" return HTML(styles)\n",
"css_styling()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Loading