
The existence of this separate matrix class should be a red flag–why would we need a separate matrix class if matrices are just 2D ndarrays? In fact, did you know that NumPy actually has a separate class named numpy.matrix? Probably not–it’s not what the Python community typically uses. But they’re not! They have some fundamental differences, and these differences are eventually going to trip you up if you’re not made aware of them. This is great, and it makes the transition to Python a lot easier.īased on these similarities, you’ll be tempted to think of the ndarray as generally equivalent to a Matlab matrix–I certainly did. NumPy arrays behave very similarly to variables in Matlab–for instance, they both support very similar syntax for making selections within a matrix. Once you have the basics of Python down, you’ll find that, in the machine learning field, we use NumPy ndarray to store our matrix and vector data. Side Note: The NumPy documentation has a very nice “quick reference” type guide on migrating from Matlab to NumPy here. Instead, I wanted to highlight some false assumptions that you may have brought with you from Matlab about how vector and matrix operations should work. Coding in Python obviously means learning a whole new programming language, with many important differences, but those aren’t the subject of this post.


It’s also likely that you have since switched from Octave to Python. Octave is great for expressing linear algebra operations cleanly, and (as I hear it) for being easier for non-programmers to get going with. If your first foray into Machine Learning was with Andrew Ng’s popular Coursera course (which is where I started back in 2012!), then you learned the fundamentals of Machine Learning using example code in “Octave” (the open-source version of Matlab).
Matlab vs python machine learning archive#
Chris McCormick About Membership Blog Archive Become an NLP expert with videos & code for BERT and beyond → Join NLP Basecamp now! Matrix Operations in NumPy vs.
