0
0
NumPydata~5 mins

np.sign() for sign detection in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the np.sign() function do in NumPy?

The np.sign() function returns the sign of each element in an array. It outputs 1 for positive numbers, -1 for negative numbers, and 0 for zeros.

Click to reveal answer
beginner
What output does np.sign() give for the input array [-3, 0, 4]?

It returns [-1, 0, 1] because -3 is negative, 0 is zero, and 4 is positive.

Click to reveal answer
intermediate
Why is np.sign() useful in data science?

It helps quickly identify if values are positive, negative, or zero. This is useful for tasks like filtering data, feature engineering, or understanding trends.

Click to reveal answer
intermediate
How does np.sign() handle floating point numbers close to zero?

It treats any positive number (even very small) as 1, any negative number as -1, and exactly zero as 0. It does not round or threshold values.

Click to reveal answer
beginner
Can np.sign() be applied to multi-dimensional arrays?

Yes, np.sign() works element-wise on arrays of any shape, returning an array of the same shape with the sign of each element.

Click to reveal answer
What does np.sign(-7) return?
A0
B-1
C1
D7
What is the output of np.sign([3, -2, 0])?
A[1, 1, 0]
B[-1, 0, 1]
C[3, -2, 0]
D[1, -1, 0]
Which of these is NOT a valid output of np.sign()?
A2
B-1
C0
D1
If an array contains only zeros, what will np.sign() return?
AAn array of zeros
BAn array of negative ones
CAn array of ones
DAn error
How does np.sign() treat very small positive numbers like 0.00001?
AReturns -1
BReturns 0
CReturns 1
DReturns the original number
Explain how np.sign() works and give an example with a small array.
Think about how it tells if numbers are positive, negative, or zero.
You got /3 concepts.
    Describe a real-life situation where detecting the sign of numbers using np.sign() could be helpful.
    Consider when knowing if a value is above or below zero matters.
    You got /3 concepts.