tan#

ivy.tan(x, /, *, out=None)[source]#

Calculate an implementation-dependent approximation to the tangent, having domain (-infinity, +infinity) and codomain (-infinity, +infinity), for each element x_i of the input array x. Each element x_i is assumed to be expressed in radians. .. note:

Tangent is an analytical function on the complex plane
and has no branch cuts. The function is periodic,
with period :math:`\pi j`, with respect to the real
component and has first order poles along the real
line at coordinates :math:`(\pi (\frac{1}{2} + n), 0)`.
However, IEEE 754 binary floating-point representation
cannot represent the value :math:`\pi / 2` exactly, and,
thus, no argument value is possible for
which a pole error occurs.

where :math:`{tanh}` is the hyperbolic tangent.

Special cases

For floating-point operands,

  • If x_i is NaN, the result is NaN.

  • If x_i is +0, the result is +0.

  • If x_i is -0, the result is -0.

  • If x_i is either +infinity or -infinity, the result is NaN.

For complex floating-point operands, special cases must be handled as if the operation is implemented as -1j * tanh(x*1j).

Parameters:
  • x (Union[Array, NativeArray]) – input array whose elements are expressed in radians. Should have a floating-point data type.

  • out (Optional[Array], default: None) – optional output, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the tangent of each element in x. The return must have a floating-point data type determined by type-promotion.

This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.

Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts ivy.Container instances in place of any of the arguments.

Examples

With ivy.Array input:

>>> x = ivy.array([0., 1., 2.])
>>> y = ivy.tan(x)
>>> print(y)
ivy.array([0., 1.56, -2.19])
>>> x = ivy.array([0.5, -0.7, 2.4])
>>> y = ivy.zeros(3)
>>> ivy.tan(x, out=y)
>>> print(y)
ivy.array([0.546, -0.842, -0.916])
>>> x = ivy.array([[1.1, 2.2, 3.3],
...                [-4.4, -5.5, -6.6]])
>>> ivy.tan(x, out=x)
>>> print(x)
ivy.array([[1.96, -1.37, 0.16],
    [-3.1, 0.996, -0.328]])

With ivy.Container input:

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = ivy.tan(x)
>>> print(y)
{
    a: ivy.array([0., 1.56, -2.19]),
    b: ivy.array([-0.143, 1.16, -3.38])
}
Array.tan(self, *, out=None)[source]#

ivy.Array instance method variant of ivy.tan. This method simply wraps the function, and so the docstring for ivy.tan also applies to this method with minimal changes.

Parameters:
  • self (Array) – input array whose elements are expressed in radians. Should have a floating-point data type.

  • out (Optional[Array], default: None) – optional output, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Array

Returns:

ret – an array containing the tangent of each element in self. The return must have a floating-point data type determined by type-promotion.

Examples

>>> x = ivy.array([0., 1., 2.])
>>> y = x.tan()
>>> print(y)
ivy.array([0., 1.56, -2.19])
Container.tan(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#

ivy.Container instance method variant of ivy.tan. This method simply wraps the function, and so the docstring for ivy.tan also applies to this method with minimal changes.

Parameters:
  • self (Container) – input array whose elements are expressed in radians. Should have a floating-point data type.

  • key_chains (Optional[Union[List[str], Dict[str, str], Container]], default: None) – The key-chains to apply or not apply the method to. Default is None.

  • to_apply (Union[bool, Container], default: True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default is True.

  • prune_unapplied (Union[bool, Container], default: False) – Whether to prune key_chains for which the function was not applied. Default is False.

  • map_sequences (Union[bool, Container], default: False) – Whether to also map method to sequences (lists, tuples). Default is False.

  • out (Optional[Container], default: None) – optional output, for writing the result to. It must have a shape that the inputs broadcast to.

Return type:

Container

Returns:

ret – a container containing the tangent of each element in self. The return must have a floating-point data type determined by type-promotion.

Examples

>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.]))
>>> y = x.tan()
>>> print(y)
{
    a:ivy.array([0., 1.56, -2.19]),
    b:ivy.array([-0.143, 1.16, -3.38])
}