Recall & Review
beginner
What does element-wise arithmetic mean when working with arrays?
Element-wise arithmetic means performing operations on each pair of corresponding elements from two arrays separately, like adding or multiplying each element one by one.
Click to reveal answer
beginner
How do you add two arrays element-wise in Python using NumPy?
You simply use the + operator between two NumPy arrays of the same shape, for example:
array1 + array2 adds each element of array1 to the corresponding element of array2.Click to reveal answer
intermediate
What happens if you try element-wise operations on arrays of different shapes?
If the shapes are not compatible, NumPy will raise an error. But if shapes are compatible by broadcasting rules, it will perform element-wise operations by stretching the smaller array.
Click to reveal answer
beginner
Show an example of element-wise multiplication of two arrays.
Example:<br><code>import numpy as np<br>a = np.array([1, 2, 3])<br>b = np.array([4, 5, 6])<br>c = a * b # c is array([4, 10, 18])</code>Click to reveal answer
beginner
Why is element-wise array arithmetic useful in data science?
It allows fast and simple calculations on datasets, like scaling, combining, or transforming data without writing loops, making code cleaner and faster.
Click to reveal answer
What does the expression
array1 + array2 do in NumPy if both arrays have the same shape?✗ Incorrect
When two arrays have the same shape, the + operator adds their elements one by one.
What will happen if you try to add arrays of shapes (3,) and (2,)?
✗ Incorrect
Arrays with incompatible shapes that cannot be broadcasted will cause an error.
Which operator is used for element-wise multiplication of two NumPy arrays?
✗ Incorrect
The * operator multiplies arrays element-wise.
If
a = np.array([1, 2, 3]) and b = np.array([4, 5, 6]), what is a * b?✗ Incorrect
Element-wise multiplication multiplies each pair: 1*4=4, 2*5=10, 3*6=18.
Why is element-wise arithmetic preferred over loops in data science?
✗ Incorrect
Element-wise operations use optimized code and avoid explicit loops, making them faster and cleaner.
Explain what element-wise arithmetic is and give an example using Python arrays.
Think about how you add or multiply numbers one by one in two lists.
You got /3 concepts.
Describe what happens when you try to perform element-wise operations on arrays with incompatible shapes.
Consider what happens if you try to add a list of 3 numbers to a list of 2 numbers.
You got /3 concepts.