0
0
NumPydata~10 mins

Why array creation matters in NumPy - Test Your Understanding

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

Complete the code to create a NumPy array from a Python list.

NumPy
import numpy as np
arr = np.[1]([1, 2, 3, 4])
print(arr)
Drag options to blanks, or click blank then click option'
Aseries
Barray
Cmatrix
Dlist
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list' instead of 'array' causes an AttributeError.
Using 'matrix' creates a different NumPy object, not a simple array.
2fill in blank
medium

Complete the code to create a 3x3 array of zeros using NumPy.

NumPy
import numpy as np
zeros_array = np.[1]((3, 3))
print(zeros_array)
Drag options to blanks, or click blank then click option'
Azeros
Bempty
Cones
Dfull
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ones' creates an array of ones, not zeros.
Using 'empty' creates an uninitialized array with random values.
3fill in blank
hard

Fix the error in the code to create an array of ones with shape 2x4.

NumPy
import numpy as np
arr = np.ones[1](2, 4)
print(arr)
Drag options to blanks, or click blank then click option'
A2, 4
B[2, 4]
C(2, 4)
D{2, 4}
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets creates a list, which is not accepted as shape.
Passing dimensions without parentheses causes a TypeError.
4fill in blank
hard

Fill both blanks to create a NumPy array of integers from 0 to 9 and reshape it to 2 rows and 5 columns.

NumPy
import numpy as np
arr = np.[1](10).[2]((2, 5))
print(arr)
Drag options to blanks, or click blank then click option'
Aarange
Breshape
Carray
Dflatten
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'array' instead of 'arange' does not generate a sequence automatically.
Using 'flatten' changes shape to 1D, not reshapes to 2D.
5fill in blank
hard

Fill all three blanks to create a 4x4 identity matrix, convert it to float type, and print its shape.

NumPy
import numpy as np
identity = np.[1](4).[2](dtype=[3])
print(identity.shape)
Drag options to blanks, or click blank then click option'
Aidentity
Bastype
Cfloat64
Dzeros
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'zeros' creates a zero matrix, not identity.
Passing dtype directly to identity instead of using astype causes an error.