Locked lesson.
About this lesson
In this video, we discuss how Numpy arrays work, including how they are much, much faster to work with than regular Python arrays.
Exercise files
Download this lesson’s related exercise files.
Numpy Arrays.docx57.1 KB Numpy Arrays - Solution.docx
55.4 KB
Quick reference
Numpy Arrays
Numpy Arrays are very much like Python Lists.
When to use
We'll use them directly and indirectly for the rest of the course.
Instructions
This is a basic Numpy Array:
np.array = [1,2,3]
Arrays can be Vectors (one dimension) or a Matrix (two dimensional).
An example of a Matrix Numpy Array is:
np.array([[1,2,3],[4,5,6],[7,8,9]])
Hints & tips
- Vector Numpy Array: np.array = [1,2,3]
- Matrix Numpy Array: np.array([[1,2,3],[4,5,6],[7,8,9]])
- 00:05 Okay, in this video, I want to talk about NumPy arrays.
- 00:08 So first off, I've got a couple of just regular Python lists here.
- 00:12 And a list is an array, Python just calls them lists, right, but
- 00:16 they're basically arrays.
- 00:17 And if you're familiar with Python,
- 00:19 you're familiar with something like these basic lists.
- 00:21 So here we have a list called names, has items John, Mary, Tim and Jill.
- 00:25 And if we print out one of those items, we can call names and
- 00:31 then say we want John, we could print the 0th item,
- 00:35 because list as you probably know are numbered and they start with 0, 1, 2, 3.
- 00:43 So if we want this one, it's the 0th item, so we can run this and boom,
- 00:47 it's John, if we want Tim, that's the 0, 1, 2, the second item, Tim.
- 00:53 And these are strings of text, but with lists,
- 00:57 you can use numbers too, so here we can print out numbers.
- 01:01 And let's say we want this one right here,
- 01:05 this is the 0, 1, one if the first item, boom 192.
- 01:10 And likewise, we could call the third item, that's 56.
- 01:15 So those are Python lists, basically, they're arrays.
- 01:18 And we're probably familiar with those if we've done any python programming.
- 01:22 NumPy arrays are basically the same, they're just written in NumPy,
- 01:26 which makes them much, much faster.
- 01:29 It makes them able to handle large amounts of data much,
- 01:32 much faster than a regular Python list.
- 01:35 And to create a NumPy array, we just go np.array and this is a function,
- 01:40 and inside of here, we can pass whatever we want.
- 01:43 So if we want 41, 192, 3, and 56,
- 01:47 we can Shift+Enter to run this and we have an array with these things in it.
- 01:54 And really, when you get right down to it, that's all there is to this, NumPy arrays.
- 01:59 Now we can do all kinds of very, very cool things to these NumPy arrays.
- 02:05 And that's what we're going to be doing in the next few videos, we'll learn
- 02:07 about operations and functions and things like that and what we can do with them.
- 02:10 But basically, it just comes down to this, they're big, they're just big arrays,
- 02:15 very much like a Python list, and that's what you want to think of them as.
- 02:18 Now, there are basically two types of arrays we want to really focus on,
- 02:22 one is called a vector and the other is called a matrix.
- 02:25 And the difference between the two are dimensions.
- 02:29 So this is a single dimension, this is just one sort of list,
- 02:33 one array inside of our NumPy array, that's just 1-dimensional.
- 02:38 That's a vector array, one dimensional arrays are vector arrays.
- 02:42 2-dimensional or above more than 1-dimension,
- 02:45 multi- dimensional are called matrices, matrix, right?
- 02:50 That's sort of what we're doing here, linear Algebra,
- 02:52 this is what this all deals with.
- 02:53 So like I said, we'll get into all this in more detail going forward, but
- 02:57 we could just create one real quick np.array.
- 03:00 And then inside of here, we can have multiple, multiple vectors,
- 03:06 I guess you would call them, right?
- 03:08 So inside of here, we could go 1, 2, 3, and inside of this one,
- 03:14 we could have 4 or 5, 6, and inside of this one we could have 7, 8, 9.
- 03:19 And when we run this we could see this is now a multi-dimensional array,
- 03:24 there are many dimensions, right?
- 03:26 If we just run this one up here like we just did, there's just one line here,
- 03:30 right, that's one dimension, it's one set of brackets, right?
- 03:35 Inside of here, we have multiple sets of brackets, multiple dimensions, and
- 03:40 this is a matrix array versus a vector.
- 03:42 So just remember vector versus matrix.
- 03:44 At this point, that's all I really want you to remember about this, that and
- 03:48 that these deal with numbers, they're arrays, they handle large amounts of data.
- 03:53 They do it faster than Python lists, which is interesting,
- 03:57 but we don't really care at this point, we just need to know from now on,
- 04:00 we're going to be using NumPy arrays for just about everything.
- 04:04 So that's really all there is to NumPy arrays right now, I mean,
- 04:08 obviously, we're going to learn a lot more about them going forward.
- 04:10 But that's all I wanted to talk about in this video, in the next video,
- 04:14 we'll start to learn about NumPy array operations, doing things to these numbers,
- 04:19 and that'll be in the next video.
Lesson notes are only available for subscribers.