Trusted answers to developer questions

Educative Team

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The ** numpy.cos() method** in Python calculates the ratio of the length of the side nearest to the angle to the length of the hypotenuse. This function returns the cosine of a number. To be more precise, it returns the cosine of a

A visual representation of the cosine ($cos$) is as follows.

```
numpy.cos(x, out=None)
```

: This method takes an array of`x`

*radian*numbers as an input.: This is an optional parameter in the`out=None`

`numpy.cos()`

function. This could be`ndarray`

,`None`

, or`tuple`

of the`ndarray`

. This parameter identifies a location where the solution or output is stored.

This method returns an `ndarray`

containing the cosine values of radian numbers from the input. The output may be scalar if the input is scalar.

import numpy as np# Creating an arrayarray = np.array([0, np.pi/2, np.pi])#Calculating the cosine of the valuesresult = np.cos(array)#Using the out parameternew_result = np.array([0, np.pi/2, np.pi])np.cos(array, out = new_result)print("Cosine of values : ", result)print("New Result array : ", new_result)

An example of the cos() function in Python

- Line 3: We create an array using the
`np.array()`

method. - Line 6: We calculate the cosine of the values in the
`array`

. - Line 9: We create a new array in this statement.
- Line 10: We calculate the cosine values and store them in the
`new_result`

array using the`out`

parameter.

Note: Providing the`out`

parameter in the`numpy.cos()`

function will store the result in the`out`

parameter, and return a reference to it.

RELATED TAGS

numpy

python

cos

trigonometry

Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring

Related Courses