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 as well, and much of the data science stuff,
0:09 Let's see how it compares. Now, NumPy is really for numbers. It might be able to store strings, but I don't know if we're gonna get any advantage.
0:16 So I'm just gonna, like the array, just have a NumPy ages and go with that. So we'll say "np" and of course we gotta do our trick up here as well.
0:28 Then we'll have an array. It's gonna be from ages, and the "dtype = int8" as well. And let's just print out one more time. Let's first print
0:43 "np_ages" just to make sure we got what we're expecting. Yeah, there's a bunch of ages local. Now let's print out the size.
0:56 Here goes. How's NumPy treating us? It's doing better than Pandas DataFrames, but you know, it's certainly nowhere near this.
1:04 So quite a powerful library here, but also not as efficient. Anyway, I think that probably is a good place to call it done.
1:16 All the things we've compared, I think that's enough. And the goal really is not even to tell you "these are better, these are worse".
1:23 The goal here is to give you a sense of scale, right? If I store it as a list relative to storing it in, say, a list of classes,
1:34 how much bigger does it get? If I store it in a number like one of these typed arrays versus stored as a pandas DataFrame,
1:41 how much bigger does that get? And you can see, there's quite a bit of variability here. So keep this, you know,
1:47 add on the own data types that you want to play with. Like, what if you're gonna store stuff in say a set instead of a list
1:52 or in a dictionary instead of a list, you could have those kinds of things as well.
1:56 Here it is, some sizes of containers compared for a whole bunch of items.


Talk Python's Mastodon Michael Kennedy's Mastodon