Complete the code to find the sign of each number in the array using np.sign().
import numpy as np arr = np.array([-3, 0, 4]) signs = np.[1](arr) print(signs)
The np.sign() function returns -1 for negative numbers, 0 for zero, and 1 for positive numbers.
Complete the code to create a boolean mask for positive numbers using np.sign().
import numpy as np arr = np.array([-2, 5, 0, 3]) mask = np.sign(arr) [1] 1 print(mask)
Using np.sign(arr) == 1 creates a mask where only positive numbers are True.
Fix the error in the code to correctly compute signs of values in the list.
import numpy as np values = [-1, 0, 2] signs = np.sign([1]) print(signs)
np.sign() works best with numpy arrays, so convert the list to an array first.
Fill both blanks to create a dictionary with words as keys and their sign of length comparison to 3 as values.
import numpy as np words = ['cat', 'dog', 'elephant'] sign_dict = {word: np.sign(len(word) [1] 3) for word in words if len(word) [2] 2} print(sign_dict)
The dictionary comprehension uses len(word) > 3 inside np.sign() to get the sign, and filters words with length >= 2.
Fill both blanks to create a dictionary with uppercase words as keys, their lengths as values, and only include words with positive sign difference from 4.
import numpy as np words = ['apple', 'bat', 'carrot', 'dog'] result = {word[1]: len(word) for word in words if np.sign(len(word) [2] 4) == 1} print(result)
The keys are uppercase words using .upper(), values are lengths, and only words longer than 4 are included.