<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <table>
 <tr align=left><td><img align=left src="https
Step1:  Python returns the floor of the 1 / 2 because we gave it integers to divide.  It then interprets the result as also needing to be an integer.  If one of the numbers was a decimal number we would have a decimal number as a result (really these are floating point numbers float).
Step2:  In compound statements it can become more difficult to figure out where possible rounding might occur so be careful when you evaluate statements.
Step3:  Python also understands imaginary numbers
Step4:  Some of the more advanced mathematical functions are stored in modules.  In order to use these functions we must first import them into our notebook and then use them.
Step5:  Variables
Variables are defined and assigned to like many other languages.
Step6:  Note that we do not get what we expect from this expression as we expected from above.  What would we have to change to get this to work?
We could go back to change our initializations but we could also use the function float to force these values to be of float type
Step7:  Control Flow
if statements are the most basic unit of logic and allows us to conditionally operate on things.
Step8:  for allows us to repeat tasks over a range of values or objects.
Step10:  Functions
Functions are a fundamental way in any language to break up the code into pieces that can be isolated and repeatedly used based on their input.
Step11:  NumPy
The most important part of NumPy is the specification of an array object called an ndarray.  This object as its name suggests stores array like information in multiple dimensions.  These objects allow a programmer to access the data in a multitude of different ways as well as create common types of arrays and operate on these arrays easily.
Step12:  Constructors
Ways to make arrays in NumPy.
Step13:  Access
How do we access data in an array?
Step14:  Manipulations
How do we manipulate arrays beyond indexing into them?
Step15:  Mathematical Functions
Step16:  Linear Algebra
Some functions for linear algebra available in NumPy.  Full implementation in scipy.linalg.
<ASSISTANT_TASK:>
Python Code:
1 / 2
Explanation: <table>
 <tr align=left><td><img align=left src="https://i.creativecommons.org/l/by/4.0/88x31.png">
 <td>Text provided under a Creative Commons Attribution license, CC-BY. All code is made available under the FSF-approved MIT license. (c) Kyle T. Mandli</td>
</table>
Review: Python
APMA 4300 Resources:
 - Intro to Python
 - Intro to NumPy
 - Intro to Matplotlib
Other resources:
 - Basic Python
 - Software Carpentry - Programming in Python
 - NumPy Intro
Installation
There are two options this semester for getting the necessary software:
1. Install on your own machine
1. Use a cloud computing platform
Your Own Machine
The easiest way to install all the components you will need for the class is to use Continuum Analytics' Anaconda distribution.  We will be using python 2.7.x for all in class demos and homework so I strongly suggest you do not get the Python 3.4 version.
Alternatives to using Anaconda also exist in the form of Enthought's Canopy distribution which provides all the tools you will need as well along with an IDE (development environment).
Cloud Computing
Instead of running things locally on your machine there are a number of cloud services that you are welcome to use in order to get everything running easily.
 1. Sage-Math-Cloud - Create an account on Sage-Math-Cloud and interact with python via the provided terminal or Ipython notebook inteface.
 1. Wakari - Continuum also has a free cloud service called Wakari that you can sign up for which provides an Anaconda installation along with similar tools to Sage-Math-Cloud.
Basic Python
Python is a dynamic, interpreted language used throughout computational engineering and science.  Due to its ease of use, cost, and available tools we will be learning the material in this course using Python tools exclusively.  For those who are coming in without prior Python knowledge but a strong programming background this lecture should acquaint you with the basics.  For people who do not know Python and do not have a strong programming background it is strongly recommended that you take the time to look through the other tutorials mentioned above.
Math
Basic math in Python is fairly straight forward with all the usual types of operations (+, -, *, /, **) which are addition, subtraction, multiplication, division and power.  Note that in Python though we need to be careful about the types of numbers we use.
End of explanation
1. / 2
Explanation: Python returns the floor of the 1 / 2 because we gave it integers to divide.  It then interprets the result as also needing to be an integer.  If one of the numbers was a decimal number we would have a decimal number as a result (really these are floating point numbers float).
End of explanation
4. + 4.0**(3.0/2)
Explanation: In compound statements it can become more difficult to figure out where possible rounding might occur so be careful when you evaluate statements.
End of explanation
4 + 3j
Explanation: Python also understands imaginary numbers:
End of explanation
import math
math?
math.sqrt(2.0)
math.sin(math.pi / 2.0)
from math import *
sin(pi)
Explanation: Some of the more advanced mathematical functions are stored in modules.  In order to use these functions we must first import them into our notebook and then use them.
End of explanation
num_students = 80
room_capacity = 85
(room_capacity - num_students) / room_capacity * 100.0
Explanation: Variables
Variables are defined and assigned to like many other languages.
End of explanation
float(room_capacity - num_students) / float(room_capacity) * 100.0
Explanation: Note that we do not get what we expect from this expression as we expected from above.  What would we have to change to get this to work?
We could go back to change our initializations but we could also use the function float to force these values to be of float type:
End of explanation
x = 4
if x > 5:
    print "x is greater than 5"
elif x < 5:
    print "x is less than 5"
else:
    print "x is equal to 5"
Explanation: Control Flow
if statements are the most basic unit of logic and allows us to conditionally operate on things.
End of explanation
for i in range(5):
    print i
for i in range(3,7):
    print i
for animal in ['cat', 'dog', 'chinchilla']:
    print animal
for n in range(2, 10):
    is_prime = True
    for x in range(2, n):
        if n % x == 0:
            print n, 'equals', x, '*', n / x
            is_prime = False
            break
    if is_prime:
        print "%s is a prime number" % (n)
Explanation: for allows us to repeat tasks over a range of values or objects.
End of explanation
def my_print_function(x):
    print x
my_print_function(3)
def my_add_function(a, b):
    return a + b, b
my_add_function(3.0, 5.0)
def my_crazy_function(a, b, c=1.0):
    d = a + b**c
    return d
my_crazy_function(2.0, 3.0), my_crazy_function(2.0, 3.0, 2.0), my_crazy_function(2.0, 3.0, c=2.0)
def my_other_function(a, b, c=1.0):
    return a + b, a + b**c, a + b**(3.0 / 7.0)
my_other_function(2.0, 3.0, c=2.0)
def fibonacci(n):
    Return a list of the Fibonacci sequence up to n
    values = [0, 1]
    while values[-1] <= n:
        values.append(values[-1] + values[-2])
        print values
    return values
fibonacci(100)
fibonacci?
Explanation: Functions
Functions are a fundamental way in any language to break up the code into pieces that can be isolated and repeatedly used based on their input.
End of explanation
import numpy
Explanation: NumPy
The most important part of NumPy is the specification of an array object called an ndarray.  This object as its name suggests stores array like information in multiple dimensions.  These objects allow a programmer to access the data in a multitude of different ways as well as create common types of arrays and operate on these arrays easily.
End of explanation
my_array = numpy.array([[1, 2], [3, 4]])
print my_array
numpy.linspace(-1, 1, 10)
numpy.zeros([3, 3])
numpy.ones([2, 3, 2])
numpy.empty([2,3])
Explanation: Constructors
Ways to make arrays in NumPy.
End of explanation
my_array[0, 1]
my_array[:,0]
my_vec = numpy.array([[1], [2]])
print my_vec
numpy.dot(my_array, my_vec)
numpy.cross?
my_array * my_vec
Explanation: Access
How do we access data in an array?
End of explanation
A = numpy.array([[1, 2, 3], [4, 5, 6]])
print "A Shape = ", A.shape
print A
B = A.reshape((6,1))
print "A Shape = ", A.shape
print "B Shape = ", B.shape
print B
numpy.tile(A, (2,2))
A.transpose()
A = numpy.array([[1,2,3],[4,5,6],[7,8,9]])
print A
print A.shape
B = numpy.arange(1,10)
print B
print B.reshape((3,3))
B.reshape?
C = B.reshape((3,3))
print A * C
numpy.dot(A, C)
Explanation: Manipulations
How do we manipulate arrays beyond indexing into them?
End of explanation
x = numpy.linspace(-2.0 * numpy.pi, 2.0 * numpy.pi, 62)
y = numpy.sin(x)
print y
x = numpy.linspace(-1, 1, 20)
numpy.sqrt(x)
x = numpy.linspace(-1, 1, 20, dtype=complex)
numpy.sqrt(x)
Explanation: Mathematical Functions
End of explanation
numpy.linalg.norm(x)
numpy.linalg.norm?
M = numpy.array([[0,2],[8,0]])
b = numpy.array([1,2])
print M
print b
x = numpy.linalg.solve(M,b)
print x
lamda,V = numpy.linalg.eig(M)
print lamda
print V
Explanation: Linear Algebra
Some functions for linear algebra available in NumPy.  Full implementation in scipy.linalg.
End of explanation
<END_TASK>