0
0
NumPydata~5 mins

Scalar operations on arrays in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What happens when you add a scalar to a NumPy array?
The scalar is added to each element of the array individually. This is called broadcasting.
Click to reveal answer
beginner
How does multiplying a NumPy array by a scalar affect the array?
Each element in the array is multiplied by the scalar, scaling all values by that number.
Click to reveal answer
beginner
What is the result of subtracting a scalar from a NumPy array?
The scalar is subtracted from each element of the array, reducing each value by that scalar.
Click to reveal answer
beginner
Can you divide a NumPy array by a scalar? What happens?
Yes, dividing a NumPy array by a scalar divides each element by that scalar, scaling down the values.
Click to reveal answer
intermediate
Why are scalar operations on arrays useful in data science?
They allow quick and easy element-wise transformations on datasets without writing loops, making code simpler and faster.
Click to reveal answer
What does adding a scalar to a NumPy array do?
AAdds the scalar to the array shape
BAdds the scalar only to the first element
CAdds the scalar to each element of the array
DThrows an error
If you multiply a NumPy array by 0, what is the result?
AAn error occurs
BThe array remains unchanged
CEach element doubles
DEach element becomes 0
Which operation scales all elements of a NumPy array by the same number?
AAdding a scalar
BMultiplying by a scalar
CChanging the array shape
DSubtracting a scalar
What happens if you divide a NumPy array by 1?
AEach element is divided by 1, so the array stays the same
BEach element becomes 1
CEach element doubles
DAn error occurs
Why are scalar operations on arrays preferred over loops in NumPy?
AThey are faster and use less code
BThey are slower but easier to write
CThey require more memory
DThey only work on 1D arrays
Explain how scalar addition works on a NumPy array and why it is useful.
Think about how adding one number affects every item in a list.
You got /4 concepts.
    Describe the effect of multiplying a NumPy array by a scalar and give a real-life example.
    Imagine increasing all prices by 10%.
    You got /3 concepts.