log#
- ivy.log(x, /, *, out=None)[source]#
 Calculate an implementation-dependent approximation to the natural (base
e) logarithm, having domain[0, +infinity]and codomain[-infinity, +infinity], for each elementx_iof the input arrayx.Special cases
For floating-point operands,
If
x_iisNaN, the result isNaN.If
x_iis less than0, the result isNaN.If
x_iis either+0or-0, the result is-infinity.If
x_iis1, the result is+0.If
x_iis+infinity, the result is+infinity.
For complex floating-point operands, let
a = real(x_i),b = imag(x_i), andIf
ais-0andbis+0, the result is-infinity + πj.If
ais+0andbis+0, the result is-infinity + 0j.If
ais a finite number andbis+infinity, the result is+infinity + πj/2.If
ais a finite number andbisNaN, the result isNaN + NaN j.If
ais-infinityandbis a positive (i.e., greater than0) finite number, the result is+infinity + πj.If
ais+infinityandbis a positive (i.e., greater than0) finite number, the result is+infinity + 0j.If
ais-infinityandbis+infinity, the result is+infinity + 3πj/4.If
ais+infinityandbis+infinity, the result is+infinity + πj/4.If
ais either+infinityor-infinityandbisNaN, the result is+infinity + NaN j.If
aisNaNandbis a finite number, the result isNaN + NaN j.If
aisNaNandbis+infinity, the result is+infinity + NaN j.If
aisNaNandbisNaN, the result isNaN + NaN j.
- Parameters:
 - Return type:
 - Returns:
 ret – an array containing the evaluated natural logarithm for each element in
x. The returned array must have a floating-point data type determined by type-promotion.
Examples
With
ivy.Arrayinput:>>> x = ivy.array([4.0, 1, -0.0, -5.0]) >>> y = ivy.log(x) >>> print(y) ivy.array([1.39, 0., -inf, nan])
>>> x = ivy.array([[float('nan'), 1, 5.0, float('+inf')], ... [+0, -1.0, -5, float('-inf')]]) >>> y = ivy.log(x) >>> print(y) ivy.array([[nan, 0., 1.61, inf], [-inf, nan, nan, nan]])
With
ivy.Containerinput:>>> x = ivy.Container(a=ivy.array([0.0, float('nan')]), ... b=ivy.array([-0., -3.9, float('+inf')]), ... c=ivy.array([7.9, 1.1, 1.])) >>> y = ivy.log(x) >>> print(y) { a: ivy.array([-inf, nan]), b: ivy.array([-inf, nan, inf]), c: ivy.array([2.07, 0.0953, 0.]) }
- Array.log(self, *, out=None)[source]#
 ivy.Array instance method variant of ivy.log. This method simply wraps the function, and so the docstring for ivy.log 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], default:None) – optional output array, for writing the result to. It must have a shape that 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
Using
ivy.Arrayinstance method:>>> x = ivy.array([4.0, 1, -0.0, -5.0]) >>> y = x.log() >>> print(y) ivy.array([1.39, 0., -inf, nan])
>>> x = ivy.array([float('nan'), -5.0, -0.0, 1.0, 5.0, float('+inf')]) >>> y = x.log() >>> print(y) ivy.array([nan, nan, -inf, 0., 1.61, inf])
>>> x = ivy.array([[float('nan'), 1, 5.0, float('+inf')], ... [+0, -1.0, -5, float('-inf')]]) >>> y = x.log() >>> print(y) ivy.array([[nan, 0., 1.61, inf], [-inf, nan, nan, nan]])
- Container.log(self, *, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
 ivy.Container instance method variant of ivy.log. This method simply wraps the function, and so the docstring for ivy.log 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],Container]], default:None) – The key-chains to apply or not apply the method to. Default isNone.to_apply (
Union[bool,Container], default:True) – If True, the method will be applied to key_chains, otherwise key_chains will be skipped. Default isTrue.prune_unapplied (
Union[bool,Container], default:False) – Whether to prune key_chains for which the function was not applied. Default isFalse.map_sequences (
Union[bool,Container], default:False) – Whether to also map method to sequences (lists, tuples). Default isFalse.out (
Optional[Container], default:None) – optional output container, for writing the result to. It must have a shape that the inputs broadcast to.
- Return type:
 Container- Returns:
 ret – a container containing the log for each element in
self. The returned array must have a real-valued floating-point data type determined by type-promotion.
Examples
Using
ivy.Containerinstance method:>>> x = ivy.Container(a=ivy.array([0.0, float('nan')]), ... b=ivy.array([-0., -3.9, float('+inf')]), ... c=ivy.array([7.9, 1.1, 1.])) >>> y = x.log() >>> print(y) { a: ivy.array([-inf, nan]), b: ivy.array([-inf, nan, inf]), c: ivy.array([2.07, 0.0953, 0.]) }