1. Welcome to Python!
Hi! Welcome to this course where you will leverage your MATLAB know-how to get you up to speed on Python for Data Science quickly.
This course is an accelerated introduction to Python meant for users who already have proficiency with MATLAB. Not sure if you’re ready for this course? I’m going to assume that you can do the following in MATLAB already.
2. Prerequisite: Manipulating matrices in MATLAB
This course expects that you know how to create, index into, and manipulate multidimensional matrices.
If the examples in the MATLAB code here are unfamiliar to you, this course probably isn't for you.
3. Prerequisite: Plotting data in MATLAB
You should be able to visualize trends in data using line plots, scatter plots, and histograms in MATLAB.
If the examples in the MATLAB code here are unfamiliar to you, this course probably isn't for you.
4. Prerequisite: Control flow of MATLAB scripts
You should be able to control the flow of a MATLAB script with if statements, while loops, and for loops.
If the examples in the MATLAB code here are unfamiliar to you, this course probably isn't for you.
5. If you don't know MATLAB...
We’re going to move fast, so if you aren’t sure about whether this is the right course, go ahead and check out some of the other introductory Python courses. You won’t hurt my feelings, I promise.
Throughout this course, I’m going to refer back to MATLAB to help give insight into how things work in Python, both the similarities and the differences. In some ways, Python and MATLAB are very similar, and you will find that things you've learned in MATLAB will easily transfer to Python.
6. Python does more than Data Science
The first notable difference to keep in mind is that Python is a general-purpose programming language with a user base that extends far beyond just the data science community. This means that you’ll be able to use Python for a much broader set of uses than MATLAB supports, from deploying machine learning models to production environments, to querying and ingesting data from a wide variety of sources, to building data-driven applications and websites.
7. Getting started with data types
Python supports multiple different data types, including integers, floats, booleans, and strings.
In the example code here, I've saved the integer "1" to the variable "x." Since there's no decimal, Python stores this as an integer. Note that unlike MATLAB, I don't need to use a semicolon at the end of the line.
On the next line, I'm passing the variable "x" to the print() function. Like MATLAB's disp(), it prints the output to the console.
We can use the type() function to identify the type of the variable and print it to the console, as well.
We can see that the type of this variable is the "int" class.
If we use a decimal, then Python saves the value as a float.
8. Mathematical operators
Python supports many mathematical operations, including addition, subtraction, multiplication, division, and exponentiation. Except for exponentiation, the operators for each of these operations are identical to their MATLAB counterparts.
How operators work depends in part on the data type they are operating on. Adding two integers together returns an integer. However, when performing an operation between an integer and a float, a float is returned.
9. Exponentiation in Python
It's important to note that the exponentiation operator differs between Python and MATLAB.
It is crucial that you get in the habit of using the double star. If you accidentally use the caret operator, Python will not throw an error, but it will do something else entirely. This can be a hard bug to catch.
10. Let's get started!
Okay, let’s start writing some Python so you can start to learn some of these differences and similarities.