# Python numpy.float_power() Examples

The following are 24 code examples for showing how to use numpy.float_power(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
```def _draw_samples(self, size, random_state):
seed = random_state.randint(0, 10**6, 1)[0]
samples = self.other_param.draw_samples(size, random_state=ia.new_random_state(seed))

elementwise = self.elementwise and not isinstance(self.val, Deterministic)

if elementwise:
exponents = self.val.draw_samples(size, random_state=ia.new_random_state(seed+1))
else:
exponents = self.val.draw_sample(random_state=ia.new_random_state(seed+1))

# without this we get int results in the case of
# Power(<int>, <stochastic float param>)
samples, exponents = both_np_float_if_one_is_float(samples, exponents)
samples_dtype = samples.dtype

# float_power requires numpy>=1.12
#result = np.float_power(samples, exponents)
# TODO why was float32 type here replaced with complex number
# formulation?
result = np.power(samples.astype(np.complex), exponents).real
if result.dtype != samples_dtype:
result = result.astype(samples_dtype)

return result ```
Example 2
```def estimate(self, query, logged_ranking, new_ranking, logged_value):
exactMatch=numpy.absolute(new_ranking-logged_ranking).sum() == 0
currentValue=0.0
if exactMatch:
numAllowedDocs=self.loggingPolicy.dataset.docsPerQuery[query]
validDocs=logged_ranking.size
invPropensity=None
if self.loggingPolicy.allowRepetitions:
invPropensity=numpy.float_power(numAllowedDocs, validDocs)
else:
invPropensity=numpy.prod(range(numAllowedDocs+1-validDocs, numAllowedDocs+1), dtype=numpy.float64)

currentValue=logged_value*invPropensity

self.updateRunningAverage(currentValue)
return self.runningMean ```
Example 3
```def estimate(self, query, logged_ranking, new_ranking, logged_value):
exactMatch=numpy.absolute(new_ranking-logged_ranking).sum() == 0
currentValue=0.0
if exactMatch:
numAllowedDocs=self.loggingPolicy.dataset.docsPerQuery[query]
validDocs=logged_ranking.size
invPropensity=None
if self.loggingPolicy.allowRepetitions:
invPropensity=numpy.float_power(numAllowedDocs, validDocs)
else:
invPropensity=numpy.prod(range(numAllowedDocs+1-validDocs, numAllowedDocs+1), dtype=numpy.float64)

currentValue=logged_value*invPropensity

self.updateRunningAverage(currentValue)
denominatorDelta=invPropensity-self.runningDenominatorMean
self.runningDenominatorMean+=denominatorDelta/self.runningSum
if self.runningDenominatorMean!=0.0:
return 1.0*self.runningMean/self.runningDenominatorMean
else:
return 0.0 ```
Example 4
```def pick_move(self, game, side):
possible_moves = game.possible_moves(side)
if len(possible_moves) == 0:
possible_moves.append((-1,-1))
monte_prob = self.monte_carlo(game, side)

if self.train:
self.temp_state.append((self.preprocess_input(game.board, side), np.divide(monte_prob, np.sum(monte_prob))))

monte_prob = np.float_power(monte_prob, 1/self.tau)
monte_prob = np.divide(monte_prob, np.sum(monte_prob))

r = random()
for i, move in enumerate(possible_moves):
r -= monte_prob[Othello.move_id(move)]
if r <= 0:
return move
return possible_moves[-1] ```
Example 5
```def plot_saliency(raw_img, image_var, img_embedding_var, caption_var):
dis = (caption_var.squeeze() * img_embedding_var.squeeze()).sum()
dis.backward(retain_graph=True)

np_img = np.array(raw_img)
return Image.fromarray(final.astype('uint8')) ```
Example 6
```def _fractal_dfa_fluctuation(segments, trends, multifractal=False, q=2):

detrended = segments - trends

if multifractal is True:
var = np.var(detrended, axis=1)
fluctuation = np.float_power(np.mean(np.float_power(var, q / 2), axis=1) / 2, 1 / q.T)
fluctuation = np.mean(fluctuation)  # Average over qs (not sure of that!)

else:
# Compute Root Mean Square (RMS)
fluctuation = np.sum(detrended ** 2, axis=1) / detrended.shape[1]
fluctuation = np.sqrt(np.sum(fluctuation) / len(fluctuation))

return fluctuation ```
Example 7
```def _fractal_mfdfa_q(q=2):
# TODO: Add log calculator for q ≈ 0

# Fractal powers as floats
q = np.asarray_chkfinite(q, dtype=np.float)

# Ensure q≈0 is removed, since it does not converge. Limit set at |q| < 0.1
q = q[(q < -0.1) + (q > 0.1)]

# Reshape q to perform np.float_power
q = q.reshape(-1, 1)
return q ```
Example 8
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 9
```def _argcheck(self, h, k):
condlist = [np.logical_and(h > 0, k > 0),
np.logical_and(h > 0, k == 0),
np.logical_and(h > 0, k < 0),
np.logical_and(h <= 0, k > 0),
np.logical_and(h <= 0, k == 0),
np.logical_and(h <= 0, k < 0)]

def f0(h, k):
return (1.0 - float_power(h, -k))/k

def f1(h, k):
return np.log(h)

def f3(h, k):
a = np.empty(np.shape(h))
a[:] = -np.inf
return a

def f5(h, k):
return 1.0/k

self.a = _lazyselect(condlist,
[f0, f1, f0, f3, f3, f5],
[h, k],
default=np.nan)

def f0(h, k):
return 1.0/k

def f1(h, k):
a = np.empty(np.shape(h))
a[:] = np.inf
return a

self.b = _lazyselect(condlist,
[f0, f1, f1, f0, f1, f1],
[h, k],
default=np.nan)
return h == h ```
Example 10
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 11
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 12
```def float_power(x1, x2):
return power(x1, x2) ```
Example 13
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 14
```def _argcheck(self, h, k):
condlist = [np.logical_and(h > 0, k > 0),
np.logical_and(h > 0, k == 0),
np.logical_and(h > 0, k < 0),
np.logical_and(h <= 0, k > 0),
np.logical_and(h <= 0, k == 0),
np.logical_and(h <= 0, k < 0)]

def f0(h, k):
return (1.0 - float_power(h, -k))/k

def f1(h, k):
return np.log(h)

def f3(h, k):
a = np.empty(np.shape(h))
a[:] = -np.inf
return a

def f5(h, k):
return 1.0/k

self.a = _lazyselect(condlist,
[f0, f1, f0, f3, f3, f5],
[h, k],
default=np.nan)

def f0(h, k):
return 1.0/k

def f1(h, k):
a = np.empty(np.shape(h))
a[:] = np.inf
return a

self.b = _lazyselect(condlist,
[f0, f1, f1, f0, f1, f1],
[h, k],
default=np.nan)
return h == h ```
Example 15
```def _draw_samples(self, size, random_state):
rngs = random_state.duplicate(2)
samples = self.other_param.draw_samples(size, random_state=rngs[0])

elementwise = (
self.elementwise
and not isinstance(self.val, Deterministic))

if elementwise:
exponents = self.val.draw_samples(size, random_state=rngs[1])
else:
exponents = self.val.draw_sample(random_state=rngs[1])

# without this we get int results in the case of
# Power(<int>, <stochastic float param>)
samples, exponents = both_np_float_if_one_is_float(samples, exponents)
samples_dtype = samples.dtype

# TODO switch to this as numpy>=1.15 is now a requirement
#      float_power requires numpy>=1.12
# result = np.float_power(samples, exponents)
# TODO why was float32 type here replaced with complex number
#      formulation?
result = np.power(samples.astype(np.complex), exponents).real
if result.dtype != samples_dtype:
result = result.astype(samples_dtype)

return result ```
Example 16
```def _draw_samples(self, size, random_state):
seed = random_state.randint(0, 10**6, 1)[0]
samples = self.other_param.draw_samples(
size,
random_state=eu.new_random_state(seed))

elementwise = self.elementwise and not isinstance(self.val, Deterministic)

if elementwise:
exponents = self.val.draw_samples(
size,
random_state=eu.new_random_state(seed+1))
else:
exponents = self.val.draw_sample(
random_state=eu.new_random_state(seed+1))

# without this we get int results in the case of
# Power(<int>, <stochastic float param>)
samples, exponents = both_np_float_if_one_is_float(samples, exponents)
samples_dtype = samples.dtype

# float_power requires numpy>=1.12
#result = np.float_power(samples, exponents)
# TODO why was float32 type here replaced with complex number
# formulation?
result = np.power(samples.astype(np.complex), exponents).real
if result.dtype != samples_dtype:
result = result.astype(samples_dtype)

return result ```
Example 17
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 18
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 19
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 20
```def _argcheck(self, h, k):
condlist = [np.logical_and(h > 0, k > 0),
np.logical_and(h > 0, k == 0),
np.logical_and(h > 0, k < 0),
np.logical_and(h <= 0, k > 0),
np.logical_and(h <= 0, k == 0),
np.logical_and(h <= 0, k < 0)]

def f0(h, k):
return (1.0 - float_power(h, -k))/k

def f1(h, k):
return np.log(h)

def f3(h, k):
a = np.empty(np.shape(h))
a[:] = -np.inf
return a

def f5(h, k):
return 1.0/k

self.a = _lazyselect(condlist,
[f0, f1, f0, f3, f3, f5],
[h, k],
default=np.nan)

def f0(h, k):
return 1.0/k

def f1(h, k):
a = np.empty(np.shape(h))
a[:] = np.inf
return a

self.b = _lazyselect(condlist,
[f0, f1, f1, f0, f1, f1],
[h, k],
default=np.nan)
return h == h ```
Example 21
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 22
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 23
```def test_type_conversion(self):
arg_type = '?bhilBHILefdgFDG'
res_type = 'ddddddddddddgDDG'
for dtin, dtout in zip(arg_type, res_type):
msg = "dtin: %s, dtout: %s" % (dtin, dtout)
arg = np.ones(1, dtype=dtin)
res = np.float_power(arg, arg)
assert_(res.dtype.name == np.dtype(dtout).name, msg) ```
Example 24
```def test_type_conversion(self):