Complete the code to compute the histogram counts of the data array.
import numpy as np data = np.array([1, 2, 2, 3, 4, 4, 4, 5]) counts, bins = np.histogram(data, bins=[1])
The bins parameter specifies the number of bins for the histogram. Here, 4 bins will group the data into 4 intervals.
Complete the code to compute histogram counts with custom bin edges.
import numpy as np data = np.array([1, 2, 2, 3, 4, 4, 4, 5]) bin_edges = [1, 2, 3, 5] counts, bins = np.histogram(data, bins=[1])
Passing a list of bin edges to bins lets you define exact intervals for the histogram.
Fix the error in the code to correctly compute histogram counts and bin edges.
import numpy as np data = np.array([1, 2, 3, 4, 5]) counts, bins = np.histogram(data, bins=[1])
The bin edges must cover the full range of data. Adding 6 as the last edge includes the last data point in the final bin.
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}
The dictionary comprehension maps each word to its length only if the word length is greater than 3.
Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] result = {{'[1]': [2] for word in words if len(word) [3] 4}}
This dictionary comprehension creates keys as uppercase words and values as their lengths, filtering words longer than 4 characters.