Welcome to AI Programming with Python

Start using AI techniques and developing skills related to programming, linear algebra, and neural networks.

Why Python Programming

Start coding with Python, drawing upon libraries and automation scripts to solve complex problems quickly.

Data Types and Operators

Control Flow

Functions

Scripting

Lab Classifying Images

In this project, learners will be testing their newly-acquired Python coding skills by using a trained image classifier. They will need to use the trained neural network to classify images of dogs (by breeds) and compare the output with the known dog breed classification. Learners will have a chance to build their own functions, use command line arguments, test the runtime of the code, create a dictionary of lists, and more.

NumPy

Learn how to use all the key tools for working with data in Python: Jupyter Notebooks, NumPy, Anaconda, Pandas, and Matplotlib.

Pandas

Matplotlib and Seaborn Part 1

Learn how to use Matplotlib to choose appropriate plots for one and two variables based on the types of data you have.

Matplotlib and Seaborn Part 2

Introduction

Learn the foundational math needed for AI success—vectors, linear transformations, and matrices—as well as the linear algebra behind neural networks.

Vectors

Linear Combination

Linear Transformation and Matrices

Vectors Lab

Linear Combination Lab

Linear Mapping Lab

Linear Algebra in Neural Networks

Introduction to Neural Networks

Gain a solid foundation in the latest trends in AI: neural networks, deep learning, and PyTorch.

Implementing Gradient Descent

Training Neural Networks

Deep Learning with PyTorch

Create Your Own Image Classifier

How Do I Continue From Here

07. Solution: Variables and Assignment Operators

Solution: Assign and Modify Variables

This is our solution to the previous quiz:

# The current volume of a water reservoir (in cubic metres)
reservoir_volume = 4.445e8
# The amount of rainfall from a storm (in cubic metres)
rainfall = 5e6

# decrease the rainfall variable by 10% to account for runoff
rainfall *= .9

# add the rainfall variable to the reservoir_volume variable
reservoir_volume += rainfall

# increase reservoir_volume by 5% to account for stormwater that flows
# into the reservoir in the days following the storm
reservoir_volume *= 1.05

# decrease reservoir_volume by 5% to account for evaporation
reservoir_volume *= 0.95

# subtract 2.5e5 cubic metres from reservoir_volume to account for water
# that's piped to arid regions.
reservoir_volume -= 2.5e5 

# print the new value of the reservoir_volume variable
print(reservoir_volume)
 

Solution: Changing Variables

For the first multiple choice quiz, the correct answer is that the value of crs_per_rab has not changed. That is, it is still 3.0.

This is because when a variable is assigned, it is assigned to the value of the expression on the right-hand-side, not to the expression itself. In the line:
“`python

crs_per_rab = carrots/rabbits

Python actually did the calculation to evaluate the expression on the right-hand-side, `carrots/rabbits`, and then assigned the variable `crs_per_rab` to be the value of that expression. It promptly forgot the formula, only saving the result in the variable.

In order to update the value of  `crs_per_rab` to take into account the change in `rabbits`, we need to run this line again:

crs_per_rab = carrots/rabbits
print(crs_per_rab)
2.0
“`
That’s the new number of carrots per rabbit after the increase in the number of rabbits. All of our variables have been updated to take this into account.