stable_pow#
- ivy.stable_pow(base, exponent, /, *, min_base=None)[source]#
Raise the base by the power, with ivy.min_base added to the base when exponent > 1 for numerical stability.
- Parameters:
- Return type:
Any
- Returns:
ret – The new item following the numerically stable power.
Examples
With
int
input:>>> x = ivy.stable_pow(2, 2) >>> print(x) ivy.array(4.00004)
>>> x = ivy.stable_pow(2, 2, min_base=2) >>> print(x) ivy.array(16)
With float input:
>>> x = ivy.stable_pow(4.0, .5) >>> print(x) ivy.array(2.00000262)
With
complex
input:>>> x = ivy.stable_pow(3+4j, 2j) >>> print(x) ivy.array(-0.15605032-0.01208451j)
With
ivy.Array
input:>>> x = ivy.asarray([[2, 4], ... [6, 8]]) >>> y = ivy.stable_pow(x, 2) >>> print(y) ivy.array([[ 4.00004, 16.00008], [36.00012, 64.00016]])
>>> x = ivy.asarray([2, 4, 6]) >>> y = ivy.asarray([2, 3, 4]) >>> z = ivy.stable_pow(x, y) >>> print(z) ivy.array([ 4.00004, 64.00048, 1296.00864])
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.asarray([2, 4]), b=ivy.asarray([6, 8])) >>> y = ivy.stable_pow(x, 2) >>> print(y) { a: ivy.array([4.00004, 16.00008]), b: ivy.array([36.00012, 64.00016]) }
>>> x = ivy.Container(a=ivy.asarray([2, 4]), b=ivy.asarray([6, 8])) >>> y = ivy.Container(a=ivy.asarray([1, 3]), b=ivy.asarray([4, 5])) >>> z = ivy.stable_pow(x, y) >>> print(z) { a: ivy.array([2.00001, 64.00048]), b: ivy.array([1296.00864, 32768.2048]) }
- Array.stable_pow(self, exponent, /, *, min_base=None)[source]#
ivy.Array instance method variant of ivy.stable_pow. This method simply wraps the function, and so the docstring for ivy.stable_pow also applies to this method with minimal changes.
- Parameters:
self (
Array
) – input array, used as the base.exponent (
Union
[Number
,Array
,NativeArray
]) – The exponent number.min_base (
Optional
[float
], default:None
) – The minimum base to use, use global ivy.min_base by default.
- Return type:
Array
- Returns:
ret – The new item following the numerically stable power.
Examples
With
ivy.Array
instance method:>>> x = ivy.asarray([2, 4]) >>> y = x.stable_pow(2) >>> print(y) ivy.array([ 4.00004, 16.00008])
>>> x = ivy.asarray([[2., 4.], [6., 8.]]) >>> y = ivy.asarray([2., 4.]) >>> z = x.stable_pow(y) >>> print(z) ivy.array([[4.00004000e+00, 2.56002560e+02], [3.60001200e+01, 4.09602048e+03]])
- Container.stable_pow(self, exponent, /, *, min_base=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False)[source]#
ivy.Container instance method variant of ivy.stable_pow. This method simply wraps the function, and so the docstring for ivy.stable_pow also applies to this method with minimal changes.
- Parameters:
self – Container of the base.
exponent (
Union
[Number
,Array
,NativeArray
,Container
]) – Container of the exponent.min_base (
Optional
[Union
[float
,Container
]], default:None
) – The minimum base to use, use global ivy.min_base by default.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 is False.
- Return type:
Container
- Returns:
ret – A container of elements containing the new items following the numerically stable power.
Examples
>>> x = ivy.Container(a=ivy.asarray([2, 4]), b=ivy.asarray([6, 8])) >>> y = x.stable_pow(2) >>> print(y) { a: ivy.array([4.00004, 16.00008]), b: ivy.array([36.00012, 64.00016]) }
>>> x = ivy.Container(a=4, b=8) >>> y = x.stable_pow(2) >>> print(y) { a: ivy.array(16.00008), b: ivy.array(64.00016) }
>>> x = ivy.Container(a=4, b=8) >>> y = ivy.asarray([1, 2]) >>> z = x.stable_pow(y) >>> print(z) { a: ivy.array([4.00001, 16.00008]), b: ivy.array([8.00001, 64.00016]) }
>>> x = ivy.Container(a=ivy.asarray([2, 4]), b=ivy.asarray([6, 8])) >>> y = ivy.Container(a=4, b=8) >>> z = x.stable_pow(y) >>> print(z) { a: ivy.array([16.00032, 256.00256]), b: ivy.array([1679638.395, 16777383.77]) }