Numpy Tutorial Python - Array Creation
Key Takeaways
The video demonstrates the use of the NumPy library in Python to create arrays, including methods such as np.zeros, np.ones, np.arange, np.linspace, np.full, np.identity, and np.random. It covers the creation of arrays with different shapes, data types, and values.
Full Transcript
[Music] hey guys and welcome to the second video in my numpy array toriel so in today's video I'm gonna be going all over all of the different ways that you can create an array and this is just gonna be without using like text files and i/o and stuff I'm gonna do that in a future video this is just gonna be ways that you can do this with straight code so nothing like reading in or reading out but I will be doing that in future videos so let's go ahead and get started so numpy has a lot of different ways or numpy sorry that you can actually create arrays that's really useful and it makes it a lot faster than doing like embedded for loops with regular lists and Python so the first way is we have this thing called NP dot zeroes and what we can do here is this is just gonna create us a list or sorry an array with the given shape so in this case 2 3 so 2 rows 3 columns of all zeros so if I run this and I print X to the screen you can see that we've gotten all zeros here and the default data type for this is a float now if I wanted to change this so that it's not a float and it actually is an int I believe I can do something like D type equals int and then if I click press X here and print this to the screen you can see that we get integers instead of floats so D type equals and you can change that to flow you can change that to string however you like there to get that so the next one it's gonna code with this it's a very similar is NP dot one's same thing we give it a shape let's just give it like 4/5 for an example here click that X and you can see again we get a array filled with ones of the given shape for 5 now we can also give a shape it's multiple dimensions like 4 or 5 3 print that to the screen and you can see we get a much longer array but just showing you that you can go ahead and do that the next method we're going to use here is actually really useful and it's numpy dot arrange and i believe it's actually a range not like as in two separate words so I'll print it out here or type it so we get a range like this and the way that this worked is just like the typical range function it's best shown with an example so I'll do that right now but it works in the same way as the standard Python range function so you see if I print this I get X then down here we get array and we get going up to 10 but not including 10 starting at 0 and array containing those numbers which again is really useful now what we can do here is we can treat this like a typical range so I do something like 5 10 and we print this out so the screen there you can see we start at 5 and go to 10 but do not include 10 so it's the same format as a typical range function start stop end or start stop step sorry so I go for example let's do 1 to 11 step by 2 and then if I print this is screen you see we get 1 3 5 7 9 like that so that's really useful and we can also do it with decimals as well so I'm just gonna bring an example I have on another thing here just to say a bit of typing so we get em Peter Ainge 2 3 go up by 0.1 print this then you can see that we get starting at 2 and then up to 2.9 okay the next one is similar but this one is gonna do a bit of math for you which actually saves us some time so this one is called linspace so I'm just gonna say x equals NP the linspace and in here we're gonna type 2 value so we're gonna start out what we want to stop at and then what to go up I believe something like that so let's just give an example here because I think I actually butchered that description and 6 okay so let's just print this the screen to see exactly what says okay so what we do here is we say we want to start at one point oh we want to go to 4.0 and we want to have sorry 6 different values in heart rate so what this does is it saves us from doing a bit of math and it's going to find out what we need to go up by to get 6 different values ranging from 1 to 4 so you can see we have one one point six two point two two point eight so on and we get six values and they automatically increment properly so evenly so that we can get the value I hope that makes sense it's not super complicated ok the next one is similar to the ones and zeros that we had this one's going to just be a constant and allow us to type in whatever value we want which is really useful as well so say x equals and P dot full so instead of zeros and ones earning full same thing we're gonna give a shape so this gets many of two two and then the value that we type in here is going to be what's filled for the entire array say x equals MP doubtful shape to two with eights and then if I show you we get constants so eights in here like so okay the next one and this is gonna be for some of you guys that know a little bit about linear algebra if you don't don't worry about it because you might be kind of confused on what this is but I am just going to show you so this is gonna give us an identity matrix of shape whatever we give it so identity matrix have these same rows and columns so we just give it one argument which is gonna be rows or columns whatever so this case I'm gonna do five and if I print this so X you can see we get an identity matrix so with our leading ones in the corresponding columns and this can be useful for doing some calculations and you can give it obviously whatever parameter you want to give it right so five six two so on okay this next one and actually the last one I'm gonna show in this video I know this was kind of short is going to be creating a random array so I don't know why you would really want to do this but if for some reason you do you can type NP dot random dot random give it a shape let's just do it for five and if you print that you will get a bunch of random values that are of type float now I just want to test this out and see if it actually works with integers I haven't done this before so hopefully it doesn't crash I expected arguments so we can't act Oh d-type is an unexpected argument yeah so we can't actually end up giving it what do you call it integers like that I believe if we wanted to just convert these into integers we just multiply every element in the array by like 100 110 something like that to give us an integer anyways that's been it for this video if you guys enjoyed please make sure you leave a like and subscribe and stay tuned for the next videos where I'm going to go through stuff like math that we can do matrix multiplication we can do a bunch of cool stuff with num num pie this is just the beginning so make sure you watch the rest of them when they come out later [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 show different ways to create 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-creation/
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 creation
- Array creation in 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: AI Productivity Tools
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