I am meant to Rewrite the following functions so that they can also be called with arrays of values. If they are called
Posted: Fri May 20, 2022 3:20 pm
I am meant to Rewrite the following functions so that they
can also be called with arrays of values. If they are called with
an array, then they should return an array containing the relevant
value for each value in the input array, e.g. the sin value for
each value in the input array.
""" a module that contains functions
for plotting the path of the sun over
the course of a day or a year"""
import math
import numpy as np
def cos_d(degrees):
""" To save us converting to radians all the time
"""
return math.cos(math.radians(degrees))
def sin_d(degrees):
""" To save us converting to radians all the time
"""
return math.sin(math.radians(degrees))
def asin_d(n):
""" Returns the degrees such that sin(degrees) ==
n
This is also know as the inverse sin function or
arcsin.
The stanard asin function returns the value in
radians.
This function converts the result to degrees
"""
return math.degrees(math.asin(n))
I am confused on how to create the array version for the
functions
Rewrite the following functions so that they can also be called with arrays of values. If they are called with an array, then they should return an array containing the relevant value for each value in the input array, e.g. the sin value for each value in the input array. See the examples below. import math def cos_d(degrees): """ To save us converting to radians all the time return math.cos(math.radians(degrees)) def sin_d(degrees): """ To save us converting to radians all the time" return math.sin(math.radians(degrees)) def asin_d(n): " Returns the degrees such that sin(degrees) == n This is also know as the inverse sin function or arcsin. The stanard asin function returns the value in radians. This function converts the result to degrees return math.degrees(math.asin(n)) Notes: You must import numpy in the standard way before defining your functions. That is: import numpy as np Your functions must still all be only 1 line long (excluding the docstrings). o This is probably easier than you think.
• You're building a module/program, so don't forget your module docstring. For yamnle
For example: Test Result [1. 0.87 0.5 0. ] [0. 0.5 0.87 1. ] values = np.array( [0, 30, 60, 90]) cozes = cos_d(values) np.set_printoptions(precision=2, suppress=True) print(cozes) values = np.array([0, 30, 60, 90]) sines= sin_d(values) np.set_printoptions(precision=2, suppress=True) print(sines) values = np.array([0, 0.5, 0.86603, 1]) asines= asin_d(values) np.set_printoptions(precision=2, suppress=True) print(asines) # calling with single values # should still work coz = cos_d(60) print(f'{coz:.2f}') [ 0. 30. 60. 90.] 0.50 Answer: inenalty recimen 5 10 15 20 25 20 an 021
can also be called with arrays of values. If they are called with
an array, then they should return an array containing the relevant
value for each value in the input array, e.g. the sin value for
each value in the input array.
""" a module that contains functions
for plotting the path of the sun over
the course of a day or a year"""
import math
import numpy as np
def cos_d(degrees):
""" To save us converting to radians all the time
"""
return math.cos(math.radians(degrees))
def sin_d(degrees):
""" To save us converting to radians all the time
"""
return math.sin(math.radians(degrees))
def asin_d(n):
""" Returns the degrees such that sin(degrees) ==
n
This is also know as the inverse sin function or
arcsin.
The stanard asin function returns the value in
radians.
This function converts the result to degrees
"""
return math.degrees(math.asin(n))
I am confused on how to create the array version for the
functions
Rewrite the following functions so that they can also be called with arrays of values. If they are called with an array, then they should return an array containing the relevant value for each value in the input array, e.g. the sin value for each value in the input array. See the examples below. import math def cos_d(degrees): """ To save us converting to radians all the time return math.cos(math.radians(degrees)) def sin_d(degrees): """ To save us converting to radians all the time" return math.sin(math.radians(degrees)) def asin_d(n): " Returns the degrees such that sin(degrees) == n This is also know as the inverse sin function or arcsin. The stanard asin function returns the value in radians. This function converts the result to degrees return math.degrees(math.asin(n)) Notes: You must import numpy in the standard way before defining your functions. That is: import numpy as np Your functions must still all be only 1 line long (excluding the docstrings). o This is probably easier than you think.

For example: Test Result [1. 0.87 0.5 0. ] [0. 0.5 0.87 1. ] values = np.array( [0, 30, 60, 90]) cozes = cos_d(values) np.set_printoptions(precision=2, suppress=True) print(cozes) values = np.array([0, 30, 60, 90]) sines= sin_d(values) np.set_printoptions(precision=2, suppress=True) print(sines) values = np.array([0, 0.5, 0.86603, 1]) asines= asin_d(values) np.set_printoptions(precision=2, suppress=True) print(asines) # calling with single values # should still work coz = cos_d(60) print(f'{coz:.2f}') [ 0. 30. 60. 90.] 0.50 Answer: inenalty recimen 5 10 15 20 25 20 an 021