0
0
NumPydata~10 mins

np.empty() for uninitialized arrays 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 create an uninitialized NumPy array of shape (3, 3).

NumPy
import numpy as np
arr = np.[1]((3, 3))
print(arr)
Drag options to blanks, or click blank then click option'
Azeros
Bempty
Cones
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.zeros() or np.ones() instead of np.empty()
Trying to pass shape as separate arguments instead of a tuple
2fill in blank
medium

Complete the code to create an uninitialized array of integers with shape (2, 4).

NumPy
import numpy as np
arr = np.empty((2, 4), dtype=[1])
print(arr)
Drag options to blanks, or click blank then click option'
Aint
Bfloat
Cstr
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'float' as dtype when integers are needed
Passing dtype as a string instead of a type
3fill in blank
hard

Fix the error in the code to create an uninitialized array of shape (5,).

NumPy
import numpy as np
arr = np.empty([1])
print(arr)
Drag options to blanks, or click blank then click option'
A(5,)
B[5]
C5
D{5}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing an integer instead of a tuple as shape
Using square brackets instead of parentheses for shape
4fill in blank
hard

Fill both blanks to create an uninitialized 2D array of floats with shape (3, 2).

NumPy
import numpy as np
arr = np.[1]([2], dtype=float)
print(arr)
Drag options to blanks, or click blank then click option'
Aempty
B(3, 2)
C[3, 2]
Dzeros
Attempts:
3 left
💡 Hint
Common Mistakes
Using zeros instead of empty
Passing shape as a list instead of a tuple
5fill in blank
hard

Fill all three blanks to create an uninitialized array with shape (4, 4), integer type, and print its shape.

NumPy
import numpy as np
arr = np.[1]([2], dtype=[3])
print(arr.shape)
Drag options to blanks, or click blank then click option'
Aempty
B(4, 4)
Cint
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Using float dtype instead of int
Passing shape as a list instead of a tuple