Logo

The Data Daily

Python for Matlab Users – Towards Data Science

Python for Matlab Users – Towards Data Science

One common issue I have noticed people are facing (especially in the Engineering world) is the transition from academia to industry. Most schools prefer having us use Matlab. Whether you are an electrical engineer, chemical engineer or even a nanoengineer, most likely you have had to use Matlab throughout your college career (other than a tiny bit of C/C++). A recent trend in industry had been the transition from Matlab to Python. This could be due to the $1000+ licensing fees, inefficiencies of memory allocation, lack of open source libraries or even the fact that most software developers hate the Matlab syntax. Lucky for us, the syntax in Matlab and Python are very similar (if you ignore the fact that Matlab indices start from 1 instead of 0). On this tutorial, I have covered the basics of Python for Matlab users, in the realm of data analytics and visualization.

While the code is available on this blog, I have also posted the same material on youtube:

One of the first things things Matlab users will be interested in will be linear algebra and matrix manipulation. Python’s math library, numpy, comes with various tools for performing simple math operations.

Let’s assume we wish to first derive the following matrix, A:

For those of you used to the simple matlab syntax, the following can be used:

However, Python logic works in terms of vectors. Hence, it is important to eventually get used to the following syntax:

Now that we have defined our matrix, we can first get the (0,0) value:

Next, we can only get the first column:

Finally, just the first row:

Now that we have managed to replicate the matrix manipulations, let’s try to perform some basic math operations. We can use the same Numpy library with the matrix A from the previous section.

Adding the values of the first row:

Dot product of A with itself:

Cross product of A with itself:

Finally, plotting is really important when visualizing data. Python’s Matplotlib function provides an extensive set of functions to perform plotting operations.

Images Powered by Shutterstock