IPython notebook Utah_Workshop/Utah_Notebooks/01-Intro-to-Python/Lesson_02_MorePython-student.ipynb
Looping through your list
make a new list of stuff
your name
favorite fruit
favorite number
favorite animal
number of siblings
favorite musician
eg. mybag = ['cindee', 'blueberry', 13, 'cat', 1, 'Lorde']
I want to refer to each item in my bag and tell you what it is
to do this I use a for loop
There are two important parts:
: colon at the end of the line
indent so python knows this is the activity at each pass
#Asking questions about things in our bag ##Sometimes we want to check the things in our bag
is my name in the bag? (what about misspelling?)
is there a cat in mybag?
Booleans?
True and False are a special type of object called Booleans
True and False are used in comparisons.
isinstance
We can use a special function called isinstance, to check if something is a string or a number
for strings use: str (short for string)
for numbers use: int (short for integer)
Exercise
See if the third thing in your bag is a number
Lets combine looping, and questions
We can loop through the things in our bag
Check if the thing is a string (use isinstance and str to make this comparison)
print the thing if it is a string
Multiple Dimensions
##What if we combined everyones bag into one bigbag?
So
##How do I access all the favorite animals?
#import and arrays
import
Python comes with a bunch of cool tools, but sometimes I need other tools (like above)
To get access to these tools I need to import them into my Python workspace
##arrays
One set of tools comes in a package called numpy
Numpy is used in data science all the time, because it allows us to easily work with lists of lists efficiently.
These objects are called arrays
Import numpy to use arrays
lets import numpy
we can even give it an alias or nickname
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-792c3430596c> in <module>()
----> 1 ones [1:,3]
TypeError: 'function' object has no attribute '__getitem__'
Images as Arrays
Now that you have exposure to arrays, lets think about how a two-dimensional array can introduce us to image processing.
Many images you see on the web are just arrays of color values, but at such a low resolution, it blends together into a smoth image.
Mona Lisa
Consider the images below.
One looks like the painting
The other looks like an array of colors
Squint your eyes, how does this impact the image on the right?
When we look into face detection, I want you to think of all the images as arrays of colors.
#Visualizing multiple dimensions using ipythonblocks
Our next session will help us get better acquianted with thinking about indexing into arrays and images as arrays. ##ipythonblocks ipython blocks allow us to understand this complex structure of multidimensional objects a little more easily
Lets create a simple set of blocks that has 4 rows and 4 columns
Colors
Colors are represented as RGB triplets
each value can range from 0 -> 255
0 is black
255 is a fully saturated color
###Exercise:
Can you make the blocks and make the whole 2nd row red and everything else black?
what other shapes can you come up with?
Advanced
Using math to generate images.
Equation for Torus
c = radius form center of hole to center of torus tube
a = radius of the tube
x = x coordinate
y = y coordinate
ParseError: KaTeX parse error: {align} can be used only in display mode.