Complete the code to calculate the absolute values of the array elements.
import numpy as np arr = np.array([-1, -2, 3, -4]) abs_arr = np.[1](arr) print(abs_arr)
The function np.abs() returns the absolute values of each element in the array.
Complete the code to find the absolute values of a 2D numpy array.
import numpy as np arr = np.array([[-1, 2], [-3, 4]]) result = np.[1](arr) print(result)
np.abs() works for arrays of any shape, returning the absolute values element-wise.
Fix the error in the code to correctly compute absolute values of the array.
import numpy as np arr = np.array([-5, 6, -7]) abs_values = np.[1](arr) print(abs_values)
The correct numpy function to get absolute values is np.abs().
Fill both blanks to create a dictionary of words and their absolute length if length is greater than 3.
words = ['data', 'ai', 'science', 'ml'] lengths = {word: [1] for word in words if [2] > 3} print(lengths)
The dictionary comprehension uses len(word) to get length and filters words with length greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and absolute length values for words longer than 2.
import numpy as np words = ['data', 'ai', 'science', 'ml'] result = { [1]: np.[2](len([3])) for word in words if len(word) > 2} print(result)
The dictionary comprehension uses uppercase words as keys, and absolute values of their lengths as values.