0
0
NumPydata~10 mins

Histogram computation with np.histogram() in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compute the histogram counts of the data array.

NumPy
import numpy as np

data = np.array([1, 2, 2, 3, 4, 4, 4, 5])
counts, bins = np.histogram(data, bins=[1])
Drag options to blanks, or click blank then click option'
A3
B4
C5
D6
Attempts:
3 left
💡 Hint
Common Mistakes
Using a number of bins that is too small or too large for the data.
Forgetting to pass the bins parameter.
2fill in blank
medium

Complete the code to compute histogram counts with custom bin edges.

NumPy
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])
Drag options to blanks, or click blank then click option'
Abin_edges
B3
C[1, 2, 3]
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a number instead of the bin edges list.
Using an incomplete list of bin edges.
3fill in blank
hard

Fix the error in the code to correctly compute histogram counts and bin edges.

NumPy
import numpy as np

data = np.array([1, 2, 3, 4, 5])
counts, bins = np.histogram(data, bins=[1])
Drag options to blanks, or click blank then click option'
A[1, 2, 3, 4]
B[1, 2, 3, 4, 5]
C[0, 1, 2, 3, 4, 5]
D[1, 2, 3, 4, 5, 6]
Attempts:
3 left
💡 Hint
Common Mistakes
Using bin edges that do not cover the maximum data value.
Using a bin edges list with the same length as data.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using the word itself instead of its length.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
result = {{'[1]': [2] for word in words if len(word) [3] 4}}
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as key without uppercase.
Using wrong comparison operator.
Swapping keys and values.