Complete the code to create a NumPy array from a Python list.
import numpy as np arr = np.[1]([1, 2, 3, 4]) print(arr)
Use np.array to create a NumPy array from a list.
Complete the code to create a 3x3 array of zeros using NumPy.
import numpy as np zeros_array = np.[1]((3, 3)) print(zeros_array)
np.zeros creates an array filled with zeros of the given shape.
Fix the error in the code to create an array of ones with shape 2x4.
import numpy as np arr = np.ones[1](2, 4) print(arr)
The shape argument must be a tuple, so use parentheses around the dimensions.
Fill both blanks to create a NumPy array of integers from 0 to 9 and reshape it to 2 rows and 5 columns.
import numpy as np arr = np.[1](10).[2]((2, 5)) print(arr)
np.arange(10) creates numbers from 0 to 9, and reshape((2, 5)) changes the shape to 2 rows and 5 columns.
Fill all three blanks to create a 4x4 identity matrix, convert it to float type, and print its shape.
import numpy as np identity = np.[1](4).[2](dtype=[3]) print(identity.shape)
np.identity(4) creates a 4x4 identity matrix, astype(float64) converts its type to float, and shape prints its dimensions.