Python Memory Management and Tips Transcripts
Chapter: Efficient data structures
Lecture: Container sizes, NumPy

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Last but not least, let's say NumPy arrays. so NumPy, the foundation of Pandas
0:06 as well, and much of the data science stuff,
0:08 Let's see how it compares. Now,
0:10 NumPy is really for numbers.
0:12 It might be able to store strings, but I don't know if we're gonna get any advantage.
0:15 So I'm just gonna, like the array,
0:16 just have a NumPy ages and go with that.
0:19 So we'll say "np" and of course
0:21 we gotta do our trick up here as well.
0:27 Then we'll have an array. It's gonna be from ages,
0:30 and the "dtype = int8" as well.
0:36 And let's just print out one more time. Let's first print
0:42 "np_ages" just to make sure we got what we're expecting.
0:46 Yeah, there's a bunch of ages local.
0:49 Now let's print out the size.
0:55 Here goes. How's NumPy treating us?
0:58 It's doing better than Pandas DataFrames,
1:00 but you know, it's certainly nowhere near this.
1:03 So quite a powerful library here,
1:08 but also not as efficient. Anyway,
1:11 I think that probably is a good place to call it done.
1:15 All the things we've compared, I think that's enough.
1:19 And the goal really is not even to tell you "these are better, these are worse".
1:22 The goal here is to give you a sense of scale,
1:26 right? If I store it as a list relative to storing it in,
1:30 say, a list of classes,
1:33 how much bigger does it get? If I store it in a number like one of
1:37 these typed arrays versus stored as a pandas DataFrame,
1:40 how much bigger does that get?
1:42 And you can see, there's quite a bit of variability here.
1:45 So keep this, you know,
1:46 add on the own data types that you want to play with.
1:48 Like, what if you're gonna store stuff in say a set instead of a list
1:51 or in a dictionary instead of a list,
1:53 you could have those kinds of things as well.
1:55 Here it is, some sizes of containers compared for a whole bunch of items.