# python has /types
print(type(1) == int)
print(type(1.) == float)
print(type(1j) == complex)
type(None)

# What happens if you add values of different types?
print(1 + 1.)

"""
Explanation: Tools

Purpose: To introduce and provide resources for the tools used to build and work with <a href="http://simpeg.xyz">SimPEG</a>

In this tutorial, we cover some of the basic tools you will need for scientific computing with Python. This follows the <a href = http://simpegtutorials.readthedocs.org/en/latest/content/tools.html>Tools</a> section of the <a href= http://simpegtutorials.readthedocs.org/>SimPEG Tutorials</a>. 
This development environment is the <a href = http://jupyter.org>Jupyter Notebook</a>. 
- To run a cell, is Shift + Enter
- To clear your kernel Esc + 00
- other keyboard shortcuts are available through the help
In this notebook, we cover some basics of:
- <a href="https://www.python.org/">Python</a>
- <a href="http://www.numpy.org/">NumPy</a>
- <a href="https://www.scipy.org/">SciPy</a>
- <a href="http://matplotlib.org/">Matplotlib</a>
Jupyter Notebook
<img src="http://blog.jupyter.org/content/images/2015/02/jupyter-sq-text.png" width="80" href="http://jupyter.org">
A <a href="">notebook</a> containing the following examples is available for you to download
and follow along. In the directory where you downloaded the notebook, open up
a <a href="http://jupyter.org">Jupyter Notebook</a> from a terminal
jupyter notebook
and open tools.ipynb. A few things to note
<img src="../../images/notebookpointers.png">

To execute a cell is Shift + Enter
To restart the kernel (clean your slate) is Esc + 00

Throughout this tutorial, we will show a few tips for working with the
notebook.
Python
<img href="https://www.python.org/" src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c3/Python-logo-notext.svg/220px-Python-logo-notext.svg.png" width=60>
Python is a high-level interpreted computing language. Here we outline a few
of the basics and common trip-ups. For more information and tutorials, check
out the <a href="https://www.python.org/doc/"Python Documentation</a>.
Types
End of explanation
"""


mylist = [6, 5, 4, 3]
type(mylist)

# length of a list
len(mylist)

# python uses zero based indexing
print(mylist[0])

print(mylist[:2]) # counting up
print(mylist[2:]) # starting from
print(mylist[-1]) # going back

"""
Explanation: Lists
End of explanation
"""


n = 10 # try making this larger --> see which is faster

%%time 
a = []
for i in range(n): # for loop assignment
    a.append(i)
print(a)

%%time
b = [i for i in range(n)]  # list comprehension
print(b)

# Enumerateing 
mylist = ['Monty', 'Python', 'Flying', 'Circus']
for i, val in enumerate(mylist):
    print(i, val)

"""
Explanation: Loops and List Comprehension
End of explanation
"""


# Pick a random number between 0 and 100
import numpy as np  # n-dimensional array package
number = (100.*np.random.rand(1)).round() # make it an integer
if number > 42:
    print('{} is too high'.format(number))
elif number < 42:
    print('{} is too low'.format(number))
else:
    print('you found the secret to life. {}'.format(number))

"""
Explanation: If, elif, else
End of explanation
"""


def pickAnumber(number):
    if number > 42:
        print('{} is too high'.format(number))
        return False
    elif number < 42:
        print('{} is too low'.format(number))
        return False
    else:
        print('you found the secret to life. {}'.format(number))
        return True

print(pickAnumber(10))

"""
Explanation: Functions
End of explanation
"""


import numpy as np

a = np.array(1) # scalar
print(a.shape)

b = np.array([1]) # vector
print(b.shape)

c = np.array([[1]]) # array
print(c.shape)

# vectors
v = np.random.rand(10)
a = v.T * v
print(a.shape)

b = v.dot(v)
b.shape

# arrays
w = np.random.rand(10,1)
w.shape

M = np.random.rand(10,10)

M*w

"""
Explanation: NumPy
End of explanation
"""


