Complete the code to find unique elements in the array.
import numpy as np arr = np.array([1, 2, 2, 3, 4, 4, 5]) unique_elements = np.[1](arr) print(unique_elements)
The np.unique() function returns the sorted unique elements of an array.
Complete the code to find unique elements and their counts.
import numpy as np arr = np.array([1, 2, 2, 3, 3, 3, 4]) unique_elements, counts = np.unique(arr, [1]=True) print(unique_elements) print(counts)
The return_counts=True argument makes np.unique() return the counts of each unique element.
Fix the error in the code to get unique elements from a 2D array.
import numpy as np arr = np.array([[1, 2], [2, 3]]) unique_elements = np.unique(arr, [1]=0) print(unique_elements)
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 elements and their counts.
import numpy as np arr = np.array([5, 6, 5, 7, 6, 8]) unique, counts = np.unique(arr, [1]=True) result = [2](zip(unique, counts)) print(result)
Use return_counts=True to get counts and dict() to create a dictionary from zipped pairs.
Fill both blanks to filter unique elements greater than 3 and create a list.
import numpy as np arr = np.array([1, 4, 4, 5, 2, 6, 3]) unique = np.unique(arr) filtered = [x for x in unique if x [1] 3] result = [2](filtered) print(result)
Use > to filter values greater than 3 and list() to create a list from the filtered values.