0
0
NumPydata~5 mins

np.union1d() for union in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AOnly values common to both arrays
BThe first array unchanged
CAll values including duplicates from both arrays
DSorted unique values from both arrays combined
If arr1 = [1, 2, 2] and arr2 = [2, 3], what is np.union1d(arr1, arr2)?
A[1, 2, 2, 3]
B[2, 3]
C[1, 2, 3]
D[1, 3]
Which of these is NOT true about np.union1d()?
AIt modifies the original arrays
BIt removes duplicates
CIt combines values from both arrays
DIt sorts the output array
What data type does np.union1d() return?
ATuple
BNumPy array
CList
DSet
Which NumPy function is best to combine two arrays and keep only unique sorted values?
Anp.union1d()
Bnp.intersect1d()
Cnp.concatenate()
Dnp.append()
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.