Complete the code to find unique values in the array.
import numpy as np arr = np.array([1, 2, 2, 3, 4, 4, 5]) unique_values = np.[1](arr) print(unique_values)
The np.unique() function returns the sorted unique elements of an array.
Complete the code to find unique values and return their counts.
import numpy as np arr = np.array([1, 2, 2, 3, 3, 3, 4]) unique_vals, counts = np.unique(arr, [1]=True) print(unique_vals, counts)
The return_counts=True argument makes np.unique() return the counts of each unique value.
Fix the error in the code to get unique values from a 2D array.
import numpy as np arr = np.array([[1, 2], [2, 3]]) unique_vals = np.unique(arr, [1]=1) print(unique_vals)
The axis parameter specifies the axis along which to find unique rows or columns in a 2D array.
Fill both blanks to create a dictionary of unique values and their counts from a list.
import numpy as np words = ['apple', 'banana', 'apple', 'orange', 'banana', 'banana'] unique_words, counts = np.unique(words, [1]=True) word_count = { [2]: counts[i] for i, [2] in enumerate(unique_words) } print(word_count)
Use return_counts=True to get counts, then create a dictionary with words as keys and counts as values.
Fill all three blanks to filter unique numbers greater than 3 and create a list of them.
import numpy as np numbers = np.array([1, 2, 3, 4, 5, 5, 6]) unique_nums = np.unique(numbers) filtered = [num for num in unique_nums if num [1] [2]] result = [3](filtered) print(result)
Filter unique numbers greater than 3 using > and 3, then convert the filtered result to a list.