Numpy Arrays Python Tutorial #3 - Array Math
Skills:
LLM Foundations60%
Key Takeaways
This video tutorial covers array math operations using the NumPy library in Python, including addition, subtraction, multiplication, and division, as well as dot products and matrix operations. The tutorial also covers array transposition and summation using NumPy's built-in functions.
Full Transcript
hey guys and welcome back to the third video in my numpy tutorial series in today's video I'm gonna be going over all of the different math operations pretty well that we can do on different arrays of different sizes I'm going to be talking about dot products inner products element wise operations a bunch of fun stuff so make sure you guys stick around for the whole video so anyways I've just got two arrays here x and y and what I want to do is I want to add the elements so like 1 plus 5 2 + 6 3 + 7 4 + 8 so on so intuitively you think you can just do this x + y and in that case you would be correct so you can apply the standard operations addition subtraction multiplication and division which I will go through now there's another way that you can do this as well and you can do NP don't add and you can do X comma Y like so and you get the exact same result again if we want to store these values we need to store them in a new array so if I do something like Z equals prints ad then we have that now stored in a new array called set next one is subtract so let's do the same thing here so X minus y you can see we get negative 4 negative 4 negative 4 negative 4 now same thing if we do NP dot subtract x + y and the exact same thing now it's the identical for multiplication and Submission but I do want to show you multiplication because some of you that know a bit about linear algebra might be confused on how this multiplication works so if I do X multiplied by Y any of you that don't know linear algebra gonna say okay I'm just gonna get 1 multiplied by 5 2 by 6 3 by 7 and you'd be correct in that case this is because we're doing element wise multiplication now what that means is we're simply just multiplying all of the corresponding elements so like Row 1 column 1 Row 2 column 2 so on we're just multiplying those together and stirring them in a new array if we want to do matrix multiplication which I'm going to show later it's a different command now same thing here we go multiply and that X Y then we get the same thing and division I don't think I need to talk about it too much we get the exact same thing element-wise and you can do em pedo divine now last one to show here and this one there's no like short form for it you have to type NP dot s QR t if you want to get the square root of every element so for example at X and we get the square root so these are useful operations and they're good to know and it's also neat that you can ignore using this like dot multiplied I'll subtract and you can simply just apply the operation like you would think you'd be able to do okay so now let's talk about dot products so I'm going to create two new arrays here I'm going to V is equal to NP ray and in this case let's just give it values of nine ten let's go W is gonna be equal to NP dot array values uh oops what am I saying here eleven and thirteen just do this why not okay so we have V and W now if I want to take the dot product of these two vectors I could go through the tedious picking out each element in the array and doing it myself but like you might assume numpy has a trick for that so we can simply do something like V dot W in this case we're gonna get a scalar which is two to nine now if you guys don't know anything about linear algebra and you don't know what this is don't worry about it simply what this dot product does is it's gonna multiply the corresponding value so we're gonna say nine x 11 plus 10 x 13 and that's the value that we get here 2 to 9 now another way we can do this is NP dot dot and then in here we'll put our two so we say V and W like so and we're gonna get the exact same answer now this dot product is only going to give us a scalar if we're multiplying vectors of the same size so we have a vector or I'm saying vector but really is an array as well of 1113 so this is a 1 by 2 and this is a 1 by 2 so that's gonna allow us to give a dot product that gives us a scalar now i want to show you an example of what happens if i multiply vectors matrix is whatever arrays of different size and show you what we get so if I do something like let's see here NP dot dot and I remember I made X&Y up here we have multiple dimensions in here so we have two rows and two columns of x and y we actually get what's known as the inner product of these matrices matrix --is so we didn't simply just dot product like all the vectors in here together and add them we actually did the inner product now I'm not gonna explain the inner product cuz now we're getting too far until linear algebra but that's how you can do that with matrixes if you guys know what those are okay now another thing that we can do is we can transpose a matrix or a vector and what that simply means to do is to write all of the rows in columns and all of the columns and rows so like vice versa so you're pretty much just flipping all of the rows into columns so I'll show you what I mean here so I'm just gonna print X and you can see that we get a matrix that goes 1 2 3 4 now if I do X dot T and this is all you have to do is just very simple this is going to transpose our matrix and you can see that we now get 1 3 2 4 so this column has been written as the row and then this column has been written as the second row again if we wanted to well reverse the operation so we said like I don't know H equals X dot T that H is gonna be our transpose matron we go 1 reverse' and you know HT and we're gonna get back to 1 2 3 4 now the last one I want to show is some now we can numpy has a built in some functions already starting and MP dot some and just give it an array here so I'm gonna give it X and you can see we get a sum of 10 plus 1 plus 3 plus 2 plus 4 all the way around 1 plus 2 Plus 3 plus 4 gives us 10 and if we want to sum just one row or or just all the rows or all the columns or so on like that we can actually do something which is really cool and suppose NP dot some will give it our array X and we can specify an axis that we want some and I'll show you what this prints up so the axis is gonna be which column you want to sum so if I do that you can see we get 4 & 6 so we have our column here which is gonna be or sorry our row actually because I said axis equals zero naught x equals 1 excuse me there so we get 1 3 which is the first sum 4 and we get 2 4 which is the second sum of 6 and it stores that in well a new array so if now if I want to sum all the columns not the rows I'll do axis is equal to 1 and you can take it 3 7 so 1 plus 2 3 plus 4 and we get 3 7 like that now I encourage you guys to play around with a lot of stuff I've shown here there's a lot of cool things you can do with them and I'm only kind of showing the basis because I want you guys to discover them on your own anyways that's been it for this video if you guys enjoyed please make sure you leave a like and subscribe and I will see you again in the next one [Music]
Original Description
In this video I explain how to implement arrays in python using the module numpy. This is a module you must download as it is not built into python. Numpy is extremely useful for using data structures and multi-dimensional lists. It has some built-in methods and properties that will save you a lot of time. In this specific tutorial I explain and show many different math operations and methods you can use on numpy arrays.
If you want to learn more about numpy and some more advanced examples stay tuned for the rest of the videos and subscribe!
Text-Based Tutorial: https://techwithtim.net/tutorials/python-module-walk-throughs/numpy-module/array-math/
Twitter: https://twitter.com/TechWithTimm
Want To Support This Channel?
Bitcoin: 1PbkAYLFaJBgjbKn2ptGyBz65xWN8hJgBU
Ethereum: 0xdd42dbbdba60f7163fc7a840e189474b6e8bfcad
Ripple: rD4arM9CVjQWqi8f1kxdpCgkCgEkqBgtud
Please leave a LIKE and SUBSCRIBE for more content!
Tags:
- Tech
- Tech With Tim
- Programming
- Coding
- Pygame
- Python Tutorials
- Numpy
- Numpy Arrays
- Arrays in python
- Numpy module
- Nump tutorial
- How to use an array in python
- Array math
- Math with arrays
- Matrixes python
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Tech With Tim · Tech With Tim · 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
A* Path Finding Algorithm(Visualization)
Tech With Tim
Python Programming Tutorial #1 - Variables and Data Types
Tech With Tim
Python Programming Tutorial #2 - Basic Operators and Input
Tech With Tim
Python Programming Tutorial #3 - Conditions
Tech With Tim
Python Programming Tutorial #4 - IF/ELIF/ELSE
Tech With Tim
Python Programming Tutorial #5 - Chained Conditionals and Nested Statements
Tech With Tim
Python Programming Tutorial #6 - For Loops
Tech With Tim
Python Programming Tutorial #7 - While Loops
Tech With Tim
Python Programming Tutorial #8 - Lists and Tuples
Tech With Tim
Python Programming Tutorial #9 - Iteration by Item (For Loops Continued...)
Tech With Tim
Python Programming Tutorial #10 - String Methods
Tech With Tim
How to Overclock a NVIDIA GPU
Tech With Tim
Python Programming Tutorial #11 - Slice Operator
Tech With Tim
Python Programming Tutorial #12 - Functions
Tech With Tim
Python Programming Tutorial #13 - How to Read a Text File
Tech With Tim
Python Programming Tutorial #14 - Writing to a Text File
Tech With Tim
Python Programming Tutorial #15 - Using .count() and .find()
Tech With Tim
Python Programming Tutorial #16 - Introduction to Modular Programming
Tech With Tim
Python Programming Tutorial #17 - Optional Parameters
Tech With Tim
Python Programming Tutorial #18 - Try and Except (Python Error Handling)
Tech With Tim
Python Programming Tutorial #19 - Global vs Local Variables
Tech With Tim
Python Programming Tutorial #20 - Classes and Objects
Tech With Tim
Cool VBS Script to Prank Your Friends!
Tech With Tim
How to Overclock an AMD GPU
Tech With Tim
Best GPU'S For Mining Ethereum (2018)
Tech With Tim
Recursion and Memoization Tutorial Python
Tech With Tim
Ethereum Mining Rig - Hardware Guide
Tech With Tim
Pygame Tutorial #1 - Basic Movement and Key Presses
Tech With Tim
How to Install Pygame (Windows 8/10)
Tech With Tim
How to Trade Your Cryptocurrency (Bitcoin, Ethereum etc.) For Cash!
Tech With Tim
How to Mine Ethereum 2018 - WORKING (Super-Easy)
Tech With Tim
Microphone Comparison - $10 Mic vs $150 Mic (Blue Yeti USB)
Tech With Tim
Pygame Tutorial #2 - Jumping and Boundaries
Tech With Tim
Pygame Tutorial #3 - Character Animation & Sprites
Tech With Tim
Pygame Tutorial #4 - Optimization & OOP
Tech With Tim
OBS Studio Tutorial - Best OBS Settings
Tech With Tim
Linear Search Algorithm - Python Example and Code
Tech With Tim
Make Any Mic Sound AMAZING! (WITH OBS)
Tech With Tim
Binary Search Algorithm - Python Example & Code
Tech With Tim
Pygame Tutorial #5 - Projectiles
Tech With Tim
Pygame Game - Mini Golf
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 1)
Tech With Tim
Pygame Tutorial - Projectile Motion (Part 2)
Tech With Tim
Pygame Tutorial #6 - Enemies
Tech With Tim
Pygame Tutorial #7 - Collision and Hit Boxes
Tech With Tim
Pygame Tutorial #8 - Scoring and Health Bars
Tech With Tim
Cloud Mining vs. Hardware Mining - 2018
Tech With Tim
How to Install Pygame on Mac OSX (Fast-Simple)
Tech With Tim
Pygame Tutorial #9 - Sound Effects, Music & More Collision
Tech With Tim
Pygame Tutorial #10 - Finishing Touches & Next Steps
Tech With Tim
How to Fade Your Screen in Pygame [CODE IN DESCRIPTION]
Tech With Tim
How to Create a Button in Pygame [CODE IN DESCRIPTION]
Tech With Tim
Pygame Side-Scroller Tutorial #1 - Scrolling Background/Character Movement
Tech With Tim
Pygame Side-Scroller Tutorial #2 - Random Object Generation
Tech With Tim
Pygame Side-Scroller Tutorial #3 - Collision
Tech With Tim
Pygame Side-Scroller Tutorial #4 - Scoring and End Screen
Tech With Tim
How to Create A Message Box in Python - Tkinter
Tech With Tim
Is Ethereum Mining Still Profitable - Is It Worth It (April 2018)
Tech With Tim
How to Run MAC OSX on a WINDOWS PC (Clover Boot-loader)
Tech With Tim
Programming Problem #1 - Alphabet Soup (Beginner/Novice)
Tech With Tim
More on: LLM Foundations
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Bloom Filters, Explained Properly
Dev.to · Daksh Gargas
Prefix Sums: The Preprocessing Trick That Makes Range Queries Instant
Medium · Programming
I Thought I Was Ready for the Interview — Then One Simple Math Question Destroyed Me
Medium · Programming
Week 2(Day 10): LeetCode Two Pointers(slow & fast): Remove Duplicates from Sorted Array (Brute…
Medium · Python
🎓
Tutor Explanation
DeepCamp AI