Sign of Each
Return an array the same length as nums where every item is 1 if the number is positive, -1 if it is negative and 0 if it is zero. Hint: np.sign.
Example 1
nums [8,-3,0,12]
returns [1,-1,0,1]
The signs are 1, -1, 0, 1.
Constraints
1 <= len(nums) <= 100
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More NumPy problems
- Sorted DistinctBeginner
- Standard DeviationBeginner
- Swap Rows and ColumnsBeginner
- Third QuartileBeginner
- Votes TallyBeginner
- Add Column OffsetsEasy
- Age GroupsEasy
- All DifferentEasy