Recall & Review
beginner
What does
np.union1d() do in NumPy?np.union1d() returns the sorted unique values that are in either of two input arrays. It combines both arrays without duplicates.
Click to reveal answer
beginner
How does
np.union1d() handle duplicate values within the input arrays?It removes duplicates and returns only unique values from both arrays combined.
Click to reveal answer
beginner
What is the output type of
np.union1d()?The output is a NumPy array containing sorted unique elements from both input arrays.
Click to reveal answer
beginner
Write a simple example of
np.union1d() with arrays [1, 2, 3] and [3, 4, 5].<pre>import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([3, 4, 5])
result = np.union1d(arr1, arr2)
print(result) # Output: [1 2 3 4 5]</pre>Click to reveal answer
beginner
Why is
np.union1d() useful in data science?It helps combine datasets or lists by merging unique values, which is useful for data cleaning and analysis.
Click to reveal answer
What does
np.union1d() return when given two arrays?✗ Incorrect
np.union1d() returns sorted unique values from both arrays combined, like a set union.
If
arr1 = [1, 2, 2] and arr2 = [2, 3], what is np.union1d(arr1, arr2)?✗ Incorrect
Duplicates are removed, so the union is [1, 2, 3].
Which of these is NOT true about
np.union1d()?✗ Incorrect
np.union1d() does not change the original arrays; it returns a new array.
What data type does
np.union1d() return?✗ Incorrect
The function returns a NumPy array with unique sorted elements.
Which NumPy function is best to combine two arrays and keep only unique sorted values?
✗ Incorrect
np.union1d() combines arrays and returns unique sorted values.
Explain how
np.union1d() works and give a simple example.Think about how sets work in math.
You got /4 concepts.
Why might you use
np.union1d() in data science projects?Consider cleaning and combining data.
You got /4 concepts.