Python's @ Operator: The Key to Better Readability in Matrix Operations
Skills:
AI Pair Programming80%
Key Takeaways
The video explains the use of Python's @ operator for matrix multiplication, enhancing code readability in AI coding applications.
Full Transcript
what is going on guys welcome back in today's video we're going to discuss one of the not so well-known python operators which is the matrix multiplication operator so let's get right into it [Music] all right so there's this python operator that a lot of you guys have probably never used before or maybe even never seen before and this is the operator for matrix multiplication now what's the idea of matrix multiplication it's quite simple we're going to import numpy S and P by the way if you don't have numpy you can just install it via the command line pip install numpy and the basic idea is the following we have a matrix A and P the dot matrix let's say one two in the First Dimension we're in the first block here in the first row of The Matrix and then three four in the second row and then we're going to copy that and we're going to say that we have also Matrix B and Matrix B is let's do 0 5. 10. 15. and the idea of a matrix multiplication now is that the Matrix c um the first the first row and First Column of C will be determined by taking those two and those two values and combining them in a certain way and how you do that I'm going to go through the manual process here you can skip that if you're not interested in that um how you do that is let's define here first of all the whole thing is none none none none um the basic idea is that the first row and First Column of C is going to be equal to the first row and First Column of a times the first row and the First Column of B and then we add to this the first row second column of a and you do the other thing on B which is you take the first uh the second the second row uh and the first column so to get this value here we take those two and those two so it's like a coordinate system a targets the row b targets the column and this is what you get as a result here now we can copy that and we can change this for the first row second column second row First Column second row second column and the basic idea is always the same you want to Target this value you take the first row uh so the a matrix specifies which Row in the B Matrix specifies which column so for this one now we're going to go again first row but we're going to go second column so what we want to do here is we want to say a stays the same basically but for B we're now going to Target the second column uh which means we're going to say 0 1 and 1 1. and then for this one so for the for the second row First Column we're going to say okay second row on a first column on B so we're going to say second row on a oh sorry and for beat stays the same and then for the last one for second row second column we want to Target the second row with a and the second column with B so we want to say one zero zero one one one one one that's a basic idea now if we print that if we print C you're going to see the result of the matrix multiplication so one two three four times zero five ten fifteen results in 20 35 40 75 that's the result of the matrix multiplication now I'm not going to go into all the details when this is necessary when this is useful just know that machine learning is basically linear algebra and linear algebra is matrix multiplication vectors all that stuff so if you're interested in machine learning you should also know about matrices and matrix multiplication or linear algebra in general but for this video here now this is just the definition of what a matrix multiplication is and with numpy we can do that way simpler by just saying print NP dot matte mall for matte multiplication for matrix multiplication and then we can specify A and B has two parameters and the result is going to be the same 20 35 40 75 that's the result of the matrix multiplication now this is not the same as calling the NP dot function this is because the NP dot function behaves differently when it comes to higher dimensions and the matte multiplication or the mat mole function or method also does not support multiplication with the scalar so those are two different methods matmo is the actual matrix multiplication now the operator this is what this video is about the operator now is the at operator like the male symbol so a at B is a matrix multiplication a matrix multiplication B so that's the same as doing that we can see that this is the case by just printing a at B and then you can see that this results in the same thing and basically again this is just syntactic sugar like a lot of stuff that we get with the different python versions this was introduced in um in Python 3.5 um and this is just making things more readable if you know that this is a matrix multiplication this is way more readable than uh constantly using NP matmo and I have actually an example for you guys I I'm going to copy paste this here this is a linear regression from scratch so this is a simple class that has a fit and predict method here and this is the linear regression implemented from scratch using this matrix multiplication operator here and then I also have the same thing using the NP matte Mall method and you can see that this is way less readable down here because you have the thing being called here three times in a row and in nested calls and you don't really know what is being multiplied by what right now you have to analyze where the commas are you have to analyze which bracket belongs to which function call and stuff like that here you exactly know okay this year is being multiplied with this this whole thing here is being multiplied with that and then this is multiplied by y That's the basic idea I also have prepared this here as two images so that you can see the difference here and that's basically all this is about this is not about performance this is not faster than using the function this is the exact same thing basically this operator calls the function math mole so it's the exact same performance but you have way better readability because you can see here clearly what is being multiplied until you have some nested function calls that you don't really that you have to analyze a little bit closer to see what is actually happening here so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you next video and bye [Music]
Original Description
Today we will learn about the "@" operator, which is used for matrix multiplication.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: https://www.neuralnine.com/books/
💻 The Algorithm Bible Book: https://www.neuralnine.com/books/
👕 Programming Merch: https://www.neuralnine.com/shop
🌐 Social Media & Contact 🌐
📱 Website: https://www.neuralnine.com/
📷 Instagram: https://www.instagram.com/neuralnine
🐦 Twitter: https://twitter.com/neuralnine
🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/
📁 GitHub: https://github.com/NeuralNine
🎙 Discord: https://discord.gg/JU4xr8U3dm
🎵 Outro Music From: https://www.bensound.com/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from NeuralNine · NeuralNine · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
The Secret Sauce of Apple Silicon: Why Unified Memory is a Game-Changer for AI
If you’ve spent…
Medium · Machine Learning
The Secret Sauce of Apple Silicon: Why Unified Memory is a Game-Changer for AI
If you’ve spent…
Medium · NLP
We Gave Our Engineering Team a Memory — Here’s How PRECOG Uses Cognee
Medium · Startup
You’ve Had the Same GPU Rumor Tab Open for Eight Months, and NVIDIA Has Never Once Confirmed the…
Medium · Machine Learning
🎓
Tutor Explanation
DeepCamp AI