0
0
Data Analysis Pythondata~10 mins

Reshaping and transposing in Data Analysis Python - Interactive Code Practice

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

Complete the code to reshape the array into 2 rows and 3 columns.

Data Analysis Python
import numpy as np
arr = np.array([1, 2, 3, 4, 5, 6])
reshaped = arr.[1]((2, 3))
print(reshaped)
Drag options to blanks, or click blank then click option'
Atranspose
Bresize
Cflatten
Dreshape
Attempts:
3 left
💡 Hint
Common Mistakes
Using flatten instead of reshape.
Using transpose which only swaps axes.
2fill in blank
medium

Complete the code to transpose the 2D array.

Data Analysis Python
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
transposed = arr.[1]()
print(transposed)
Drag options to blanks, or click blank then click option'
Atranspose
BT
Creshape
Dflatten
Attempts:
3 left
💡 Hint
Common Mistakes
Using reshape instead of transpose.
Using T without parentheses (T is an attribute, not a method).
3fill in blank
hard

Fix the error in reshaping the array to 3 rows and 2 columns.

Data Analysis Python
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
reshaped = np.[1](arr, (3, 2))
print(reshaped)
Drag options to blanks, or click blank then click option'
Aflatten
Bresize
Creshape
Dtranspose
Attempts:
3 left
💡 Hint
Common Mistakes
Using reshape which causes an error due to size mismatch.
Using transpose which does not change shape like this.
4fill in blank
hard

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

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

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

Data Analysis Python
data = {'a': 1, 'b': -2, 'c': 3}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys instead of uppercase.
Using < instead of > in the condition.