Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Aggregate Functions | Introduction to NumPy
Introduction to Data Analysis in Python
course content

Kursinnhold

Introduction to Data Analysis in Python

Introduction to Data Analysis in Python

1. Basics
2. Data Types
3. Control Flow
4. Functions and Modules
5. Introduction to NumPy

book
Aggregate Functions

You can also calculate aggregate statistics of NumPy arrays, like minimum, maximum, mean, product, sum, etc. These ase realized in NumPy as arrays methods.

MethodDescription
.mean()Returns the arithmetic mean
.sum()Returns the sum of elements
.prod()Returns the product of all elements
.min()Returns the minimum of an array
.max()Returns the maximum of an array
.std()Returns the standard deviation of array elements
.var()Returns the variance of array elements

For example, assume we have two arrays: prices and sales, representing goods' prices and quantity of each good being sold, respectively. Using multiplication and .sum() method we can easily calculate the total revenue.

12345678910
# Import the library import numpy as np # Two arrays prices = np.array([15, 60, 40, 5]) sales = np.array([7, 3, 5, 15]) # Revenue per good rev_per_good = prices * sales # Total revenue print("Total revenue is", rev_per_good.sum())
copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 4

Spør AI

expand
ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

course content

Kursinnhold

Introduction to Data Analysis in Python

Introduction to Data Analysis in Python

1. Basics
2. Data Types
3. Control Flow
4. Functions and Modules
5. Introduction to NumPy

book
Aggregate Functions

You can also calculate aggregate statistics of NumPy arrays, like minimum, maximum, mean, product, sum, etc. These ase realized in NumPy as arrays methods.

MethodDescription
.mean()Returns the arithmetic mean
.sum()Returns the sum of elements
.prod()Returns the product of all elements
.min()Returns the minimum of an array
.max()Returns the maximum of an array
.std()Returns the standard deviation of array elements
.var()Returns the variance of array elements

For example, assume we have two arrays: prices and sales, representing goods' prices and quantity of each good being sold, respectively. Using multiplication and .sum() method we can easily calculate the total revenue.

12345678910
# Import the library import numpy as np # Two arrays prices = np.array([15, 60, 40, 5]) sales = np.array([7, 3, 5, 15]) # Revenue per good rev_per_good = prices * sales # Total revenue print("Total revenue is", rev_per_good.sum())
copy

Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 4
Vi beklager at noe gikk galt. Hva skjedde?
some-alt