本文整理匯總了Python中numpy.remainder方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.remainder方法的具體用法?Python numpy.remainder怎麽用?Python numpy.remainder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.remainder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _ecg_simulate_derivsecgsyn
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def _ecg_simulate_derivsecgsyn(t, x, rr, ti, sfint, ai, bi):
ta = math.atan2(x[1], x[0])
r0 = 1
a0 = 1.0 - np.sqrt(x[0] ** 2 + x[1] ** 2) / r0
ip = np.floor(t * sfint).astype(int)
w0 = 2 * np.pi / rr[min(ip, len(rr) - 1)]
# w0 = 2*np.pi/rr[ip[ip <= np.max(rr)]]
fresp = 0.25
zbase = 0.005 * np.sin(2 * np.pi * fresp * t)
dx1dt = a0 * x[0] - w0 * x[1]
dx2dt = a0 * x[1] + w0 * x[0]
# matlab rem and numpy rem are different
# dti = np.remainder(ta - ti, 2*np.pi)
dti = (ta - ti) - np.round((ta - ti) / 2 / np.pi) * 2 * np.pi
dx3dt = -np.sum(ai * dti * np.exp(-0.5 * (dti / bi) ** 2)) - 1 * (x[2] - zbase)
dxdt = np.array([dx1dt, dx2dt, dx3dt])
return dxdt
示例2: get_cdf_values
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def get_cdf_values(array, bins):
# array = np.transpose(array)
n_rows = array.shape[0]
n_cols = array.shape[1]
array_t = np.zeros((n_rows, n_cols))
parts = n_rows / bins
hist_values = np.zeros(n_rows)
sorted_hist_values = np.zeros(n_rows)
for row in range(n_rows):
if np.remainder(bins, 2) == 1:
hist_values[row] = np.floor(np.divide(row, parts)) / (bins - 1)
else:
hist_values[row] = np.floor(np.divide(row, parts)) / bins
for col in range(n_cols):
order = np.argsort(array[:, col], axis=0)
sorted_hist_values = hist_values[order]
array_t[:, col] = sorted_hist_values
return array_t
示例3: test_remainder_basic
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def test_remainder_basic(self):
dt = np.typecodes['AllInteger'] + np.typecodes['Float']
for dt1, dt2 in itertools.product(dt, dt):
for sg1, sg2 in itertools.product((+1, -1), (+1, -1)):
if sg1 == -1 and dt1 in np.typecodes['UnsignedInteger']:
continue
if sg2 == -1 and dt2 in np.typecodes['UnsignedInteger']:
continue
fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s'
msg = fmt % (dt1, dt2, sg1, sg2)
a = np.array(sg1*71, dtype=dt1)
b = np.array(sg2*19, dtype=dt2)
div = np.floor_divide(a, b)
rem = np.remainder(a, b)
assert_equal(div*b + rem, a, err_msg=msg)
if sg2 == -1:
assert_(b < rem <= 0, msg)
else:
assert_(b > rem >= 0, msg)
示例4: test_float_remainder_exact
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def test_float_remainder_exact(self):
# test that float results are exact for small integers. This also
# holds for the same integers scaled by powers of two.
nlst = list(range(-127, 0))
plst = list(range(1, 128))
dividend = nlst + [0] + plst
divisor = nlst + plst
arg = list(itertools.product(dividend, divisor))
tgt = list(divmod(*t) for t in arg)
a, b = np.array(arg, dtype=int).T
# convert exact integer results from Python to float so that
# signed zero can be used, it is checked.
tgtdiv, tgtrem = np.array(tgt, dtype=float).T
tgtdiv = np.where((tgtdiv == 0.0) & ((b < 0) ^ (a < 0)), -0.0, tgtdiv)
tgtrem = np.where((tgtrem == 0.0) & (b < 0), -0.0, tgtrem)
for dt in np.typecodes['Float']:
msg = 'dtype: %s' % (dt,)
fa = a.astype(dt)
fb = b.astype(dt)
div = np.floor_divide(fa, fb)
rem = np.remainder(fa, fb)
assert_equal(div, tgtdiv, err_msg=msg)
assert_equal(rem, tgtrem, err_msg=msg)
示例5: test_float_remainder_roundoff
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def test_float_remainder_roundoff(self):
# gh-6127
dt = np.typecodes['Float']
for dt1, dt2 in itertools.product(dt, dt):
for sg1, sg2 in itertools.product((+1, -1), (+1, -1)):
fmt = 'dt1: %s, dt2: %s, sg1: %s, sg2: %s'
msg = fmt % (dt1, dt2, sg1, sg2)
a = np.array(sg1*78*6e-8, dtype=dt1)
b = np.array(sg2*6e-8, dtype=dt2)
div = np.floor_divide(a, b)
rem = np.remainder(a, b)
# Equal assertion should hold when fmod is used
assert_equal(div*b + rem, a, err_msg=msg)
if sg2 == -1:
assert_(b < rem <= 0, msg)
else:
assert_(b > rem >= 0, msg)
示例6: sampling
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def sampling(self, range_max, v_id=None, prev_failed=False):
assert range_max > 0, \
ValueError("range_max = {}".format(range_max))
interval = self.rng.choice(self.interval)
if self.num == 1:
return [self.rng.choice(range(0, range_max))]
# sampling
speed_min = self.speed[0]
speed_max = min(self.speed[1], (range_max-1)/((self.num-1)*interval))
if speed_max < speed_min:
return (np.remainder(np.arange(0, self.num * interval, interval), range_max)).tolist()
random_interval = self.rng.uniform(speed_min, speed_max) * interval
frame_range = (self.num-1) * random_interval
clip_start = self.rng.uniform(0, (range_max-1) - frame_range)
clip_end = clip_start + frame_range
return np.linspace(clip_start, clip_end, self.num).astype(dtype=np.int).tolist()
示例7: frame_to_state_mapping
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def frame_to_state_mapping(shift_file, lab_file, fs, states_per_phone=5):
#Read files:
v_shift = lu.read_binfile(shift_file, dim=1)
v_pm = la.shift_to_pm(v_shift)
m_state_times = np.loadtxt(lab_file, usecols=(0,1))
# to miliseconds:
v_pm_ms = 1000 * v_pm / fs
m_state_times_ms = m_state_times / 10000.0
# Compare:
nfrms = len(v_pm_ms)
v_st = np.zeros(nfrms) - 1 # init
for f in xrange(nfrms):
vb_greater = (v_pm_ms[f] >= m_state_times_ms[:,0]) # * (v_pm_ms[f] < m_state_times_ms[:,1])
state_nx = np.where(vb_greater)[0][-1]
v_st[f] = np.remainder(state_nx, states_per_phone)
return v_st
#==============================================================================
示例8: from_molecular_shingling
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def from_molecular_shingling(self, tokens):
"""Creates the hash set for a string array and returns it without changing the hash values of
this instance.
Arguments:
a {numpy.ndarray} -- A string array.
Returns:
numpy.ndarray -- An array containing the hash values.
"""
hash_values = np.zeros([self.n_permutations, 1], dtype=np.uint32)
hash_values.fill(MHFPEncoder.max_hash)
for t in tokens:
t_h = struct.unpack("<I", sha1(t).digest()[:4])[0]
hashes = np.remainder(
np.remainder(
self.permutations_a * t_h + self.permutations_b, MHFPEncoder.prime
),
self.max_hash,
)
hash_values = np.minimum(hash_values, hashes)
return hash_values.reshape((1, self.n_permutations))[0]
示例9: from_sparse_array
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def from_sparse_array(self, array):
"""Creates the hash set for a sparse binary array and returns it without changing the hash
values of this instance. This is useful when a molecular shingling is already hashed.
Arguments:
s {numpy.ndarray} -- A sparse binary array.
Returns:
numpy.ndarray -- An array containing the hash values.
"""
hash_values = np.zeros([self.n_permutations, 1], dtype=np.uint32)
hash_values.fill(MHFPEncoder.max_hash)
for i in array:
hashes = np.remainder(
np.remainder(
self.permutations_a * i + self.permutations_b, MHFPEncoder.prime
),
self.max_hash,
)
hash_values = np.minimum(hash_values, hashes)
return hash_values.reshape((1, self.n_permutations))[0]
示例10: from_binary_array
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def from_binary_array(self, array):
"""Creates the hash set for a binary array and returns it without changing the hash
values of this instance. This is useful to minhash a folded fingerprint.
Arguments:
s {numpy.ndarray} -- A sparse binary array.
Returns:
numpy.ndarray -- A binary array.
"""
hash_values = np.zeros([self.n_permutations, 1], dtype=np.uint32)
hash_values.fill(MHFPEncoder.max_hash)
for i, v in enumerate(array):
if v == 1:
hashes = np.remainder(
np.remainder(
self.permutations_a * i + self.permutations_b, MHFPEncoder.prime
),
self.max_hash,
)
hash_values = np.minimum(hash_values, hashes)
return hash_values.reshape((1, self.n_permutations))[0]
示例11: fit
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def fit(self, magnitude, time, PeriodLS, Amplitude, phase_bins, mag_bins):
first_period = PeriodLS[0]
lc_yaxis = (magnitude - np.min(magnitude)) / np.float(Amplitude)
# SHIFT TO BEGIN AT MINIMUM
loc = np.argmin(lc_yaxis)
lc_phase = np.remainder(time - time[loc], first_period) / first_period
bins = (phase_bins, mag_bins)
signature = np.histogram2d(lc_phase, lc_yaxis, bins=bins, normed=True)[
0
]
return {"SignaturePhMag": signature}
示例12: floor_divide_and_remainder
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def floor_divide_and_remainder(x, y):
return (np.floor_divide(x, y), np.remainder(x, y))
示例13: test_float_remainder_corner_cases
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def test_float_remainder_corner_cases(self):
# Check remainder magnitude.
for dt in np.typecodes['Float']:
b = np.array(1.0, dtype=dt)
a = np.nextafter(np.array(0.0, dtype=dt), -b)
rem = np.remainder(a, b)
assert_(rem <= b, 'dt: %s' % dt)
rem = np.remainder(-a, -b)
assert_(rem >= -b, 'dt: %s' % dt)
# Check nans, inf
with suppress_warnings() as sup:
sup.filter(RuntimeWarning, "invalid value encountered in remainder")
for dt in np.typecodes['Float']:
fone = np.array(1.0, dtype=dt)
fzer = np.array(0.0, dtype=dt)
finf = np.array(np.inf, dtype=dt)
fnan = np.array(np.nan, dtype=dt)
rem = np.remainder(fone, fzer)
assert_(np.isnan(rem), 'dt: %s, rem: %s' % (dt, rem))
# MSVC 2008 returns NaN here, so disable the check.
#rem = np.remainder(fone, finf)
#assert_(rem == fone, 'dt: %s, rem: %s' % (dt, rem))
rem = np.remainder(fone, fnan)
assert_(np.isnan(rem), 'dt: %s, rem: %s' % (dt, rem))
rem = np.remainder(finf, fone)
assert_(np.isnan(rem), 'dt: %s, rem: %s' % (dt, rem))
示例14: reflective_transformation
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def reflective_transformation(y, lb, ub):
"""Compute reflective transformation and its gradient."""
if in_bounds(y, lb, ub):
return y, np.ones_like(y)
lb_finite = np.isfinite(lb)
ub_finite = np.isfinite(ub)
x = y.copy()
g_negative = np.zeros_like(y, dtype=bool)
mask = lb_finite & ~ub_finite
x[mask] = np.maximum(y[mask], 2 * lb[mask] - y[mask])
g_negative[mask] = y[mask] < lb[mask]
mask = ~lb_finite & ub_finite
x[mask] = np.minimum(y[mask], 2 * ub[mask] - y[mask])
g_negative[mask] = y[mask] > ub[mask]
mask = lb_finite & ub_finite
d = ub - lb
t = np.remainder(y[mask] - lb[mask], 2 * d[mask])
x[mask] = lb[mask] + np.minimum(t, 2 * d[mask] - t)
g_negative[mask] = t > d[mask]
g = np.ones_like(y)
g[g_negative] = -1
return x, g
# Functions to display algorithm's progress.
示例15: test_float_remainder_corner_cases
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import remainder [as 別名]
def test_float_remainder_corner_cases(self):
# Check remainder magnitude.
for dt in np.typecodes['Float']:
b = np.array(1.0, dtype=dt)
a = np.nextafter(np.array(0.0, dtype=dt), -b)
rem = np.remainder(a, b)
assert_(rem <= b, 'dt: %s' % dt)
rem = np.remainder(-a, -b)
assert_(rem >= -b, 'dt: %s' % dt)
# Check nans, inf
with warnings.catch_warnings():
warnings.simplefilter('always')
warnings.simplefilter('ignore', RuntimeWarning)
for dt in np.typecodes['Float']:
fone = np.array(1.0, dtype=dt)
fzer = np.array(0.0, dtype=dt)
finf = np.array(np.inf, dtype=dt)
fnan = np.array(np.nan, dtype=dt)
rem = np.remainder(fone, fzer)
assert_(np.isnan(rem), 'dt: %s, rem: %s' % (dt, rem))
# MSVC 2008 returns NaN here, so disable the check.
#rem = np.remainder(fone, finf)
#assert_(rem == fone, 'dt: %s, rem: %s' % (dt, rem))
rem = np.remainder(fone, fnan)
assert_(np.isnan(rem), 'dt: %s, rem: %s' % (dt, rem))
rem = np.remainder(finf, fone)
assert_(np.isnan(rem), 'dt: %s, rem: %s' % (dt, rem))