Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does the numpy function np.sin() compute?
The function np.sin() computes the sine of each element in the input array, where the input is in radians.
Click to reveal answer
beginner
How is the cosine function represented in numpy?
The cosine function is represented by np.cos(), which calculates the cosine of each input value in radians.
Click to reveal answer
beginner
What is the output of np.tan(np.pi / 4)?
The output is 1.0 because the tangent of 45 degrees (π/4 radians) is 1.
Click to reveal answer
intermediate
Why do numpy trigonometric functions expect input in radians, not degrees?
Because radians are the standard unit for angles in mathematical functions and calculations, numpy functions like np.sin(), np.cos(), and np.tan() expect input in radians for accuracy and consistency.
Click to reveal answer
beginner
How can you convert degrees to radians before using numpy trigonometric functions?
You can convert degrees to radians using np.radians(degrees), which converts degree values to radians for use in np.sin(), np.cos(), and np.tan().
Click to reveal answer
What does np.cos(np.pi) return?
A1.0
B0.0
CUndefined
D-1.0
✗ Incorrect
The cosine of π radians (180 degrees) is -1.0.
Which numpy function calculates the tangent of an angle?
Anp.sin()
Bnp.arctan()
Cnp.tan()
Dnp.cos()
✗ Incorrect
np.tan() calculates the tangent of each element in the input array.
If you have an angle in degrees, which function helps convert it to radians?
Anp.degrees()
Bnp.radians()
Cnp.sin()
Dnp.tan()
✗ Incorrect
np.radians() converts degrees to radians, which is needed for trigonometric functions.
What is the value of np.sin(0)?
A0
B1
C-1
DUndefined
✗ Incorrect
The sine of 0 radians is 0.
Which unit should angles be in when using np.sin(), np.cos(), or np.tan()?
ARadians
BDegrees
CGradians
DTurns
✗ Incorrect
Numpy trigonometric functions expect angles in radians.
Explain how to calculate the sine, cosine, and tangent of an angle using numpy, including any necessary unit conversions.
Think about the input unit and the numpy functions for each trig function.
You got /3 concepts.
Describe a real-life example where you might use numpy's trigonometric functions in data science.
Consider situations involving cycles or angles.
You got /3 concepts.
Practice
(1/5)
1. What does the numpy function np.sin() calculate when given an angle in radians?
easy
A. The angle converted from radians to degrees.
B. The cosine of the angle, which is the ratio of the adjacent side to the hypotenuse.
C. The tangent of the angle, which is the ratio of the opposite side to the adjacent side.
D. The sine of the angle, which is the ratio of the opposite side to the hypotenuse in a right triangle.
Solution
Step 1: Understand the function purpose
The function np.sin() calculates the sine value of an angle given in radians.
Step 2: Recall sine definition in triangles
Sine of an angle is the ratio of the length of the opposite side to the hypotenuse in a right triangle.
Final Answer:
The sine of the angle, which is the ratio of the opposite side to the hypotenuse in a right triangle. -> Option D
Quick Check:
np.sin() gives sine ratio [OK]
Hint: Remember sin = opposite/hypotenuse in triangles [OK]
Common Mistakes:
Confusing sine with cosine or tangent
Thinking np.sin() converts radians to degrees
Using degrees directly without conversion
2. Which of the following is the correct way to calculate the cosine of 60 degrees using numpy?
easy
A. np.cos(np.radians(60))
B. np.cos(np.sin(60))
C. np.cos(np.degrees(60))
D. np.cos(60)
Solution
Step 1: Recognize angle units for numpy trig functions
numpy trigonometric functions expect angles in radians, not degrees.
Step 2: Convert degrees to radians before using np.cos()
Use np.radians(60) to convert 60 degrees to radians, then apply np.cos().
Final Answer:
np.cos(np.radians(60)) -> Option A
Quick Check:
Convert degrees to radians before trig functions [OK]
Hint: Always convert degrees to radians with np.radians() [OK]
4. The following code is intended to calculate the tangent of 45 degrees but gives an incorrect result. What is the error?
import numpy as np
tan_45 = np.tan(45)
print(tan_45)
medium
A. np.tan() cannot calculate tangent for 45 degrees.
B. The angle 45 should be converted to radians before using np.tan().
C. The code should use np.tan(np.degrees(45)) instead.
D. The print statement is missing parentheses.
Solution
Step 1: Identify input units for np.tan()
numpy trigonometric functions require angles in radians, not degrees.
Step 2: Correct the input by converting degrees to radians
Use np.radians(45) to convert 45 degrees before passing to np.tan().
Final Answer:
The angle 45 should be converted to radians before using np.tan(). -> Option B
Quick Check:
Convert degrees to radians before np.tan() [OK]
Hint: Always convert degrees to radians before trig functions [OK]
Common Mistakes:
Passing degrees directly to np.tan()
Using np.degrees() instead of np.radians()
Assuming np.tan() works with degrees
5. You have an array of angles in degrees: angles = np.array([30, 45, 60]). You want to create a new array that contains the tangent values of these angles but only include values where the tangent is less than 2. Which code correctly does this?
hard
A. tan_vals = np.tan(np.radians(angles)); filtered = tan_vals[tan_vals < 2]
B. tan_vals = np.tan(angles); filtered = tan_vals[tan_vals < 2]
C. tan_vals = np.tan(np.degrees(angles)); filtered = tan_vals[tan_vals < 2]
D. tan_vals = np.tan(np.radians(angles)); filtered = tan_vals[tan_vals > 2]
Solution
Step 1: Convert degrees to radians for tangent calculation
Use np.radians(angles) to convert the array of degrees to radians before applying np.tan().
Step 2: Filter tangent values less than 2
Use boolean indexing tan_vals[tan_vals < 2] to select values less than 2.