log1p#
- ivy.log1p(x, /, *, out=None)[source]#
Calculate an implementation-dependent approximation to log(1+x), where log refers to the natural (base e) logarithm. .. note:
The purpose of this function is to calculate ``log(1+x)`` more accurately when `x` is close to zero. Accordingly, conforming implementations should avoid implementing this function as simply ``log(1+x)``. See FDLIBM, or some other IEEE 754-2019 compliant mathematical library, for a potential reference implementation.
Special cases
For floating-point operands,
If
x_i
isNaN
, the result isNaN
.If
x_i
is less than-1
, the result isNaN
.If
x_i
is-1
, the result is-infinity
.If
x_i
is-0
, the result is-0
.If
x_i
is+0
, the result is+0
.If
x_i
is+infinity
, the result is+infinity
.
- Parameters:
- Return type:
- Returns:
ret – an array containing the evaluated Natural logarithm of 1 + x for each element in
x
. The returned array 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 # noqa 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([1 , 2 ,3 ]) >>> y = ivy.log1p(x) >>> print(y) ivy.array([0.693, 1.1 , 1.39 ])
>>> x = ivy.array([0 , 1 ]) >>> y = ivy.zeros(2) >>> ivy.log1p(x , out = y) >>> print(y) ivy.array([0. , 0.693])
>>> x = ivy.array([[1.1, 2.2, 3.3],[4.4, 5.5, 6.6]]) >>> ivy.log1p(x, out = x) >>> print(x) ivy.array([[0.742, 1.16 , 1.46 ],[1.69 , 1.87 , 2.03 ]])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([0., 1., 2.]), b=ivy.array([3., 4., 5.1])) >>> y = ivy.log1p(x) >>> print(y) { a: ivy.array([0., 0.693, 1.1]), b: ivy.array([1.39, 1.61, 1.81]) }
- Array.log1p(self, *, out=None)#
ivy.Array instance method variant of ivy.log1p. This method simply wraps the function, and so the docstring for ivy.log1p also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array. Should have a real-valued floating-point data type.out (
Optional
[Array
]) – optional output array, for writing the result to. It must have a shape that (default:None
) the inputs broadcast to.
- Return type:
Array
- Returns:
ret – an array containing the evaluated result for each element in
self
. The returned array must have a real-valued floating-point data type determined by type-promotion.
Examples
>>> x = ivy.array([1 , 2 ,3 ]) >>> y = x.log1p() >>> print(y) ivy.array([0.693, 1.1 , 1.39 ])
>>> x = ivy.array([0.1 , .001 ]) >>> x.log1p(out = x) >>> print(x) ivy.array([0.0953, 0.001 ])
- Container.log1p(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)#
ivy.Container instance method variant of ivy.log1p. This method simply wraps the function, and so the docstring for ivy.log1p also applies to this method with minimal changes.
- Parameters:
self (
Container
) – input container. Should have a real-valued floating-point data type.key_chains (
Optional
[Union
[List
[str
],Dict
[str
,str
]]]) – The key-chains to apply or not apply the method to. Default isNone
. (default:None
)to_apply (
bool
) – If True, the method will be applied to key_chains, otherwise key_chains (default:True
) will be skipped. Default isTrue
.prune_unapplied (
bool
) – Whether to prune key_chains for which the function was not applied. (default:False
) Default isFalse
.map_sequences (
bool
) – Whether to also map method to sequences (lists, tuples). (default:False
) Default isFalse
.out (
Optional
[Container
]) – optional output container, for writing the result to. It must have a shape (default:None
) that the inputs broadcast to.
- Return type:
Container
- Returns:
ret – a container containing the evaluated result for each element in
self
. The returned array must have a real-valued floating-point data type determined by type-promotion.
Examples
>>> x = ivy.Container(a=ivy.array([1.6, 2.6, 3.5]), ... b=ivy.array([4.5, 5.3, 2.3])) >>> y = x.log1p() >>> print(y) { a: ivy.array([0.956, 1.28, 1.5]), b: ivy.array([1.7, 1.84, 1.19]) }