0
0
NumPydata~20 mins

What is NumPy - Practice Questions & Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
NumPy Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
What is the primary purpose of NumPy?

NumPy is a popular Python library. What is its main use?

ATo perform fast numerical computations with arrays and matrices.
BTo create interactive web pages.
CTo manage databases and SQL queries.
DTo build machine learning models without data preprocessing.
Attempts:
2 left
💡 Hint

Think about what kind of data structure NumPy mainly works with.

Predict Output
intermediate
1:30remaining
What is the output of this NumPy code?

Look at the code below. What will it print?

NumPy
import numpy as np
arr = np.array([1, 2, 3])
print(arr * 2)
A[1 2 3 1 2 3]
BTypeError: unsupported operand type(s) for *: 'list' and 'int'
C[3 4 5]
D[2 4 6]
Attempts:
2 left
💡 Hint

Multiplying a NumPy array by a number multiplies each element.

data_output
advanced
1:30remaining
What is the shape of the resulting NumPy array?

Consider this code creating a 2D array. What is the shape of arr?

NumPy
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr.shape)
A(1, 6)
B(6,)
C(2, 3)
D(3, 2)
Attempts:
2 left
💡 Hint

Count rows and columns in the nested list.

🔧 Debug
advanced
1:30remaining
What error does this NumPy code raise?

What error will this code produce?

NumPy
import numpy as np
arr = np.array([1, 2, 3])
print(arr[3])
AIndexError: index 3 is out of bounds for axis 0 with size 3
BTypeError: 'int' object is not subscriptable
CValueError: could not broadcast input array
DSyntaxError: invalid syntax
Attempts:
2 left
💡 Hint

Remember Python indexing starts at 0 and the last index is length-1.

🚀 Application
expert
2:00remaining
Which option produces the correct mean of a NumPy array?

Given arr = np.array([1, 2, 3, 4, 5]), which code correctly calculates the mean?

NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
Aarr.sum() / arr.size
Ball of the above
Cnp.mean(arr)
Darr.mean()
Attempts:
2 left
💡 Hint

Think about different ways to calculate average in NumPy.