Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Implementing Basic Functions in Python | Functions and Their Properties
Mathematics for Data Science

bookImplementing Basic Functions in Python

Functions define relationships between inputs and outputs, making them fundamental in mathematics, programming, and data science. In Python, we can define and visualize different types of functions, such as one-to-one, many-to-one, onto, into, and bijective functions.

Types of Functions in Python

If you're excited to dive into python, try out these following functions – and see if you can predict their outputs!

One-to-One (Injective) Function

A one-to-one function ensures that each input maps to a unique output. As you'll see, no two inputs have the same output.

123456789
# One-to-One Function: f(x) = x def one_to_one(x): return x # Example Outputs print("One-to-One Function Outputs:") print(one_to_one(2)) # Output is 2 print(one_to_one(5)) # Output is 5
copy

Many-to-One Function

A many-to-one function allows multiple inputs to map to the same output.

12345678
# Many-to-One Function: f(x) = x^2 def many_to_one(x): return x ** 2 # Example Outputs print("\nMany-to-One Function Outputs:") print(many_to_one(3)) # Output is 9 print(many_to_one(-3)) # Output is also 9 (Same output for different inputs)
copy

Onto (Surjective) Function

An onto function ensures that every possible output in the codomain has at least one input mapped to it.

123456789
# Onto Function: f(x) = tan(x) def onto(x): return np.tan(x) # Example Outputs print("\nOnto Function Outputs:") print(onto(1)) # Output is approximately 1.557 print(onto(-1)) # Output is approximately -2.185
copy

Into Function

An into function means not all values in the codomain are covered—some outputs remain unused.

12345678
# Into Function: f(x) = sin(x) (Only outputs between -1 and 1) def into(x): return np.sin(x) # Example Outputs print("\nInto Function Outputs:") print(into(0)) # Output is approximately 0 print(into(np.pi / 2)) # Output is approximately 1
copy

Bijective Function (One-to-One & Onto)

A bijective function is both one-to-one and onto, meaning it is invertible.

12345678
# Bijective Function: f(x) = x def bijective(x): return x # Example Outputs print("\nBijective Function Outputs:") print(bijective(3)) # Output is 3 print(bijective(-4)) # Output is -4
copy

1. What will the following function return for f(4)f(4)?

2. Which function ensures every value in the codomain has a pre-image?

3. What will be the output of the many_to_one function for -5?

4. Which function does NOT cover the entire codomain?

question mark

What will the following function return for f(4)f(4)?

Select the correct answer

question mark

Which function ensures every value in the codomain has a pre-image?

Select the correct answer

question mark

What will be the output of the many_to_one function for -5?

Select the correct answer

question mark

Which function does NOT cover the entire codomain?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Awesome!

Completion rate improved to 1.89

bookImplementing Basic Functions in Python

Swipe um das Menü anzuzeigen

Functions define relationships between inputs and outputs, making them fundamental in mathematics, programming, and data science. In Python, we can define and visualize different types of functions, such as one-to-one, many-to-one, onto, into, and bijective functions.

Types of Functions in Python

If you're excited to dive into python, try out these following functions – and see if you can predict their outputs!

One-to-One (Injective) Function

A one-to-one function ensures that each input maps to a unique output. As you'll see, no two inputs have the same output.

123456789
# One-to-One Function: f(x) = x def one_to_one(x): return x # Example Outputs print("One-to-One Function Outputs:") print(one_to_one(2)) # Output is 2 print(one_to_one(5)) # Output is 5
copy

Many-to-One Function

A many-to-one function allows multiple inputs to map to the same output.

12345678
# Many-to-One Function: f(x) = x^2 def many_to_one(x): return x ** 2 # Example Outputs print("\nMany-to-One Function Outputs:") print(many_to_one(3)) # Output is 9 print(many_to_one(-3)) # Output is also 9 (Same output for different inputs)
copy

Onto (Surjective) Function

An onto function ensures that every possible output in the codomain has at least one input mapped to it.

123456789
# Onto Function: f(x) = tan(x) def onto(x): return np.tan(x) # Example Outputs print("\nOnto Function Outputs:") print(onto(1)) # Output is approximately 1.557 print(onto(-1)) # Output is approximately -2.185
copy

Into Function

An into function means not all values in the codomain are covered—some outputs remain unused.

12345678
# Into Function: f(x) = sin(x) (Only outputs between -1 and 1) def into(x): return np.sin(x) # Example Outputs print("\nInto Function Outputs:") print(into(0)) # Output is approximately 0 print(into(np.pi / 2)) # Output is approximately 1
copy

Bijective Function (One-to-One & Onto)

A bijective function is both one-to-one and onto, meaning it is invertible.

12345678
# Bijective Function: f(x) = x def bijective(x): return x # Example Outputs print("\nBijective Function Outputs:") print(bijective(3)) # Output is 3 print(bijective(-4)) # Output is -4
copy

1. What will the following function return for f(4)f(4)?

2. Which function ensures every value in the codomain has a pre-image?

3. What will be the output of the many_to_one function for -5?

4. Which function does NOT cover the entire codomain?

question mark

What will the following function return for f(4)f(4)?

Select the correct answer

question mark

Which function ensures every value in the codomain has a pre-image?

Select the correct answer

question mark

What will be the output of the many_to_one function for -5?

Select the correct answer

question mark

Which function does NOT cover the entire codomain?

Select the correct answer

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 2
some-alt