Complete the code to calculate the standard deviation of the array.
import numpy as np arr = np.array([1, 2, 3, 4, 5]) std_dev = np.[1](arr) print(std_dev)
The np.std() function calculates the standard deviation, which measures how spread out the numbers are.
Complete the code to calculate the variance of the array.
import numpy as np arr = np.array([10, 20, 30, 40, 50]) variance = np.[1](arr) print(variance)
The np.var() function calculates the variance, which is the average of the squared differences from the mean.
Fix the error in the code to correctly calculate the standard deviation.
import numpy as np values = [2, 4, 6, 8] result = np.std([1]) print(result)
NumPy functions work best with NumPy arrays. Converting the list to an array ensures correct calculation.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = {word: [1] for word in words if len(word) [2] 3} print(lengths)
The dictionary comprehension uses len(word) to get the length and filters words with length greater than 3 using >.
Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.
words = ['tree', 'house', 'river', 'sky', 'mountain'] result = { [1]: [2] for word in words if len(word) [3] 4 } print(result)
The dictionary comprehension uses the uppercase word as the key (word.upper()), the length as the value (len(word)), and filters words longer than 4 characters (>).