Unit 27Aggregating and Ordering Arrays

Data ordering and aggregation are at the core of data science. You start with large amounts of data and gradually distill them by binning, averaging, accumulating, and so on, until they hopefully boil down to a small, easily presentable, and easily interpretable set. numpy provides the functions mean, sum, std (standard deviation), min, and max that return the respective aggregated measures of a numpy array.

Let’s use a combination of broadcasting, aggregation functions, ufuncs, and Boolean indexes—almost our entire toolset!—to extract the stocks from Unit 25, Demystifying Universal Functions, that changed either way by more than the average eight-stock portfolio:

 sap[ np.abs(stocks[0] - stocks[1]) ...

Get Data Science Essentials in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.