Complete the code to check if any element in the array is True.
import numpy as np arr = np.array([False, False, True, False]) result = np.[1](arr) print(result)
The np.any() function returns True if at least one element in the array is True.
Complete the code to check if all elements in the array are True.
import numpy as np arr = np.array([True, True, True]) result = np.[1](arr) print(result)
The np.all() function returns True only if every element in the array is True.
Fix the error in the code to correctly check if any element is True along axis 0.
import numpy as np arr = np.array([[False, True], [False, False]]) result = np.any(arr, axis=[1]) print(result)
Axis 0 means checking down the rows (columns). Using axis=0 checks each column for any True value.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if all characters are alphabetic.
words = ['apple', 'banana', '123', 'pear'] lengths = {word: len(word) for word in words if word.[1]() and all(c.[2]() for c in word)} print(lengths)
The isalpha() method checks if all characters in a string are letters. The comprehension filters words where word.isalpha() is True and all characters c.isalpha() are letters.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths only if any character is uppercase and all characters are alphabetic.
words = ['Apple', 'BANANA', '123', 'Pear'] result = {word.[1](): len(word) for word in words if any(c.[2]() for c in word) and all(c.[3]() for c in word)} print(result)
The comprehension converts words to uppercase with word.upper(). It includes words where any character is uppercase (c.isupper()) and all characters are alphabetic (c.isalpha()).