0
0
Data Analysis Pythondata~20 mins

Array arithmetic (element-wise) in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Array Arithmetic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Element-wise addition of NumPy arrays
What is the output of this code snippet that adds two NumPy arrays element-wise?
Data Analysis Python
import numpy as np

arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
result = arr1 + arr2
print(result)
A[1 2 3 4 5 6]
BTypeError
C[4 7 9]
D[5 7 9]
Attempts:
2 left
💡 Hint
Think about how NumPy adds arrays of the same shape.
data_output
intermediate
2:00remaining
Element-wise multiplication with broadcasting
Given the arrays below, what is the output of the element-wise multiplication?
Data Analysis Python
import numpy as np

arr1 = np.array([[1, 2, 3], [4, 5, 6]])
arr2 = np.array([10, 20, 30])
result = arr1 * arr2
print(result)
A
[[10 20 30]
 [40 50 60]]
B
[[10 40 90]
 [40 100 180]]
C
[[10 20 30 10 20 30]
 [40 50 60 40 50 60]]
DValueError
Attempts:
2 left
💡 Hint
Remember how broadcasting works when multiplying arrays of different shapes.
🔧 Debug
advanced
2:00remaining
Identify the error in element-wise division
What error does this code raise when performing element-wise division?
Data Analysis Python
import numpy as np

arr1 = np.array([1, 2, 0])
arr2 = np.array([0, 2, 3])
result = arr1 / arr2
print(result)
ARuntimeWarning: divide by zero encountered in true_divide
BValueError
CTypeError
DZeroDivisionError
Attempts:
2 left
💡 Hint
Look carefully at division by zero in NumPy arrays.
visualization
advanced
2:00remaining
Plotting element-wise addition result
Which option correctly plots the element-wise addition of two arrays as a line chart?
Data Analysis Python
import numpy as np
import matplotlib.pyplot as plt

arr1 = np.array([1, 3, 5, 7])
arr2 = np.array([2, 4, 6, 8])
result = arr1 + arr2
plt.plot(result)
plt.show()
AA scatter plot with points [1, 3, 5, 7]
BA bar chart with bars at heights [3, 7, 11, 15]
CA line chart with points [3, 7, 11, 15] connected by lines
DAn empty plot with no data
Attempts:
2 left
💡 Hint
plt.plot draws a line chart by default connecting the points.
🧠 Conceptual
expert
2:00remaining
Effect of element-wise operations on array shape
If you multiply a (3,1) shaped NumPy array by a (1,4) shaped array element-wise, what is the shape of the result?
A(3, 4)
B(3, 1)
C(1, 4)
DValueError
Attempts:
2 left
💡 Hint
Think about how broadcasting expands dimensions to match.