Recall & Review
beginner
What does
np.intersect1d() do?It finds the common elements between two arrays and returns them as a sorted array without duplicates.
Click to reveal answer
beginner
How does
np.intersect1d() handle duplicates in input arrays?It removes duplicates and returns only unique common elements in the output.
Click to reveal answer
beginner
Example: What is the output of
np.intersect1d([1, 2, 3], [2, 3, 4])?The output is
array([2, 3]) because 2 and 3 are common in both arrays.Click to reveal answer
intermediate
Can
np.intersect1d() be used with arrays of different data types?Yes, but the arrays should be compatible types so that comparison is possible.
Click to reveal answer
intermediate
What is the difference between
np.intersect1d() and Python's set intersection?np.intersect1d() works on numpy arrays and returns a sorted array without duplicates, while set intersection works on Python sets and returns an unordered set.Click to reveal answer
What does
np.intersect1d() return?✗ Incorrect
np.intersect1d() returns the sorted unique elements common to both arrays.
If
a = [1, 2, 2, 3] and b = [2, 2, 4], what is np.intersect1d(a, b)?✗ Incorrect
Duplicates are removed, so only one 2 is returned.
Which of these is true about
np.intersect1d()?✗ Incorrect
The output is always sorted and unique.
Can
np.intersect1d() be used with string arrays?✗ Incorrect
It works with any arrays where elements can be compared, including strings.
What happens if there are no common elements between arrays?
✗ Incorrect
If no elements match, the result is an empty array.
Explain how
np.intersect1d() works and give a simple example.Think about finding shared items in two lists.
You got /3 concepts.
Describe the difference between
np.intersect1d() and Python set intersection.Consider data types and output format.
You got /3 concepts.