本文整理汇总了Python中numpy.floor_divide方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.floor_divide方法的具体用法?Python numpy.floor_divide怎么用?Python numpy.floor_divide使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.floor_divide方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: w
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def w(w_max, w_min, step):
linspace_lower = (np.floor_divide(w_min, step)+1)*step
N = np.floor_divide(w_max-w_min, step)
linspace_upper = linspace_lower + N*step
w = np.linspace(linspace_lower, linspace_upper, int(N)+1)
if not np.isclose(w[0], w_min, atol=step/5.):
w = np.concatenate((np.array([w_min]), w))
if not np.isclose(w[-1], w_max, atol=step/5.):
w = np.concatenate((w,np.array([w_max])))
return w, len(w)
# Compute dielectric function using Lorentzian model.
# Units of w and ResFreq must match and must be directly proportional to angular frequency. All other parameters are unitless.
示例2: w
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def w(w_max, w_min, step):
linspace_lower = (np.floor_divide(w_min, step)+1)*step
N = np.floor_divide(w_max-w_min, step)
linspace_upper = linspace_lower + N*step
w = np.linspace(linspace_lower, linspace_upper, int(N)+1)
if not np.isclose(w[0], w_min, atol=step/5.):
w = np.concatenate((np.array([w_min]), w))
if not np.isclose(w[-1], w_max, atol=step/5.):
w = np.concatenate((w,np.array([w_max])))
return w, len(w)
# Compute dielectric function using Brendel-Bormann (aka Gaussian or Gaussian-convoluted Drude–Lorentz) model.
# Units of w and ResFreq must match and must be directly proportional to angular frequency. All other parameters are unitless.
示例3: test_NotImplemented_not_returned
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def test_NotImplemented_not_returned(self):
# See gh-5964 and gh-2091. Some of these functions are not operator
# related and were fixed for other reasons in the past.
binary_funcs = [
np.power, np.add, np.subtract, np.multiply, np.divide,
np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
np.logical_and, np.logical_or, np.logical_xor, np.maximum,
np.minimum, np.mod,
np.greater, np.greater_equal, np.less, np.less_equal,
np.equal, np.not_equal]
a = np.array('1')
b = 1
c = np.array([1., 2.])
for f in binary_funcs:
assert_raises(TypeError, f, a, b)
assert_raises(TypeError, f, c, a)
示例4: test_NotImplemented_not_returned
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def test_NotImplemented_not_returned(self):
# See gh-5964 and gh-2091. Some of these functions are not operator
# related and were fixed for other reasons in the past.
binary_funcs = [
np.power, np.add, np.subtract, np.multiply, np.divide,
np.true_divide, np.floor_divide, np.bitwise_and, np.bitwise_or,
np.bitwise_xor, np.left_shift, np.right_shift, np.fmax,
np.fmin, np.fmod, np.hypot, np.logaddexp, np.logaddexp2,
np.logical_and, np.logical_or, np.logical_xor, np.maximum,
np.minimum, np.mod
]
# These functions still return NotImplemented. Will be fixed in
# future.
# bad = [np.greater, np.greater_equal, np.less, np.less_equal, np.not_equal]
a = np.array('1')
b = 1
for f in binary_funcs:
assert_raises(TypeError, f, a, b)
示例5: test_remainder_basic
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [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)
示例6: test_float_remainder_exact
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [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)
示例7: __init__
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def __init__(self, roi_center=None, roi_size=None, roi_start=None, roi_end=None):
"""
Args:
roi_center (list or tuple): voxel coordinates for center of the crop ROI.
roi_size (list or tuple): size of the crop ROI.
roi_start (list or tuple): voxel coordinates for start of the crop ROI.
roi_end (list or tuple): voxel coordinates for end of the crop ROI.
"""
if roi_center is not None and roi_size is not None:
roi_center = np.asarray(roi_center, dtype=np.uint16)
roi_size = np.asarray(roi_size, dtype=np.uint16)
self.roi_start = np.subtract(roi_center, np.floor_divide(roi_size, 2))
self.roi_end = np.add(self.roi_start, roi_size)
else:
assert roi_start is not None and roi_end is not None, "roi_start and roi_end must be provided."
self.roi_start = np.asarray(roi_start, dtype=np.uint16)
self.roi_end = np.asarray(roi_end, dtype=np.uint16)
assert np.all(self.roi_start >= 0), "all elements of roi_start must be greater than or equal to 0."
assert np.all(self.roi_end > 0), "all elements of roi_end must be positive."
assert np.all(self.roi_end >= self.roi_start), "invalid roi range."
示例8: testFloatBasic
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def testFloatBasic(self):
x = np.linspace(-5, 20, 15).reshape(1, 3, 5).astype(np.float32)
y = np.linspace(20, -5, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(x, y, np.add, tf.add, also_compare_variables=True)
self._compareBoth(x, y, np.subtract, tf.sub)
self._compareBoth(x, y, np.multiply, tf.mul)
self._compareBoth(x, y + 0.1, np.true_divide, tf.truediv)
self._compareBoth(x, y + 0.1, np.floor_divide, tf.floordiv)
self._compareBoth(x, y, np.add, _ADD)
self._compareBoth(x, y, np.subtract, _SUB)
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y + 0.1, np.true_divide, _TRUEDIV)
self._compareBoth(x, y + 0.1, np.floor_divide, _FLOORDIV)
try:
from scipy import special # pylint: disable=g-import-not-at-top
a_pos_small = np.linspace(0.1, 2, 15).reshape(1, 3, 5).astype(np.float32)
x_pos_small = np.linspace(0.1, 10, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(a_pos_small, x_pos_small, special.gammainc, tf.igamma)
self._compareBoth(a_pos_small, x_pos_small, special.gammaincc, tf.igammac)
# Need x > 1
self._compareBoth(x_pos_small + 1, a_pos_small, special.zeta, tf.zeta)
n_small = np.arange(0, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(n_small, x_pos_small, special.polygamma, tf.polygamma)
except ImportError as e:
tf.logging.warn("Cannot test special functions: %s" % str(e))
示例9: testDoubleBasic
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def testDoubleBasic(self):
x = np.linspace(-5, 20, 15).reshape(1, 3, 5).astype(np.float64)
y = np.linspace(20, -5, 15).reshape(1, 3, 5).astype(np.float64)
self._compareBoth(x, y, np.add, tf.add)
self._compareBoth(x, y, np.subtract, tf.sub)
self._compareBoth(x, y, np.multiply, tf.mul)
self._compareBoth(x, y + 0.1, np.true_divide, tf.truediv)
self._compareBoth(x, y + 0.1, np.floor_divide, tf.floordiv)
self._compareBoth(x, y, np.add, _ADD)
self._compareBoth(x, y, np.subtract, _SUB)
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y + 0.1, np.true_divide, _TRUEDIV)
self._compareBoth(x, y + 0.1, np.floor_divide, _FLOORDIV)
try:
from scipy import special # pylint: disable=g-import-not-at-top
a_pos_small = np.linspace(0.1, 2, 15).reshape(1, 3, 5).astype(np.float32)
x_pos_small = np.linspace(0.1, 10, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(a_pos_small, x_pos_small, special.gammainc, tf.igamma)
self._compareBoth(a_pos_small, x_pos_small, special.gammaincc, tf.igammac)
except ImportError as e:
tf.logging.warn("Cannot test special functions: %s" % str(e))
示例10: testInt32Basic
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def testInt32Basic(self):
x = np.arange(1, 13, 2).reshape(1, 3, 2).astype(np.int32)
y = np.arange(1, 7, 1).reshape(1, 3, 2).astype(np.int32)
self._compareBoth(x, y, np.add, tf.add)
self._compareBoth(x, y, np.subtract, tf.sub)
self._compareBoth(x, y, np.multiply, tf.mul)
self._compareBoth(x, y, np.true_divide, tf.truediv)
self._compareBoth(x, y, np.floor_divide, tf.floordiv)
self._compareBoth(x, y, np.mod, tf.mod)
self._compareBoth(x, y, np.add, _ADD)
self._compareBoth(x, y, np.subtract, _SUB)
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y, np.true_divide, _TRUEDIV)
self._compareBoth(x, y, np.floor_divide, _FLOORDIV)
self._compareBoth(x, y, np.mod, _MOD)
# _compareBoth tests on GPU only for floating point types, so test
# _MOD for int32 on GPU by calling _compareGpu
self._compareGpu(x, y, np.mod, _MOD)
示例11: test_csr_from_coo_novals
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def test_csr_from_coo_novals():
for i in range(50):
coords = np.random.choice(np.arange(50 * 100, dtype=np.int32), 1000, False)
rows = np.mod(coords, 100, dtype=np.int32)
cols = np.floor_divide(coords, 100, dtype=np.int32)
csr = lm.CSR.from_coo(rows, cols, None, (100, 50))
assert csr.nrows == 100
assert csr.ncols == 50
assert csr.nnz == 1000
for i in range(100):
sp = csr.rowptrs[i]
ep = csr.rowptrs[i+1]
assert ep - sp == np.sum(rows == i)
points, = np.nonzero(rows == i)
po = np.argsort(cols[points])
points = points[po]
assert all(np.sort(csr.colinds[sp:ep]) == cols[points])
assert np.sum(csr.row(i)) == len(points)
示例12: process_image
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def process_image(img_id):
if 'Pan-Sharpen_' in img_id:
img_id = img_id.split('Pan-Sharpen_')[1]
img = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'Pan-Sharpen', 'Pan-Sharpen_' + img_id+'.tif'))
nir = img[:, :, 3:]
img = img[:, :, :3]
np.clip(img, None, threshold, out=img)
img = np.floor_divide(img, threshold / 255).astype('uint8')
cv2.imwrite(path.join(test_png, img_id + '.png'), img, [cv2.IMWRITE_PNG_COMPRESSION, 9])
img2 = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'MS', 'MS_' + img_id+'.tif'))
img2 = np.rollaxis(img2, 0, 3)
img2 = cv2.resize(img2, (900, 900), interpolation=cv2.INTER_LANCZOS4)
img_0_3_5 = (np.clip(img2[..., [0, 3, 5]], None, (2000, 3000, 3000)) / (np.array([2000, 3000, 3000]) / 255)).astype('uint8')
cv2.imwrite(path.join(test_png2, img_id + '.png'), img_0_3_5, [cv2.IMWRITE_PNG_COMPRESSION, 9])
pan = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'PAN', 'PAN_' + img_id+'.tif'))
pan = pan[..., np.newaxis]
img_pan_6_7 = np.concatenate([pan, img2[..., 7:], nir], axis=2)
img_pan_6_7 = (np.clip(img_pan_6_7, None, (3000, 5000, 5000)) / (np.array([3000, 5000, 5000]) / 255)).astype('uint8')
cv2.imwrite(path.join(test_png3, img_id + '.png'), img_pan_6_7, [cv2.IMWRITE_PNG_COMPRESSION, 9])
示例13: median
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def median(self):
ordered = numpy.lexsort((self._ts['values'], self.indexes))
# TODO(gordc): can use np.divmod when centos supports numpy 1.13
mid_diff = numpy.floor_divide(self.counts, 2)
odd = numpy.mod(self.counts, 2)
mid_floor = (numpy.cumsum(self.counts) - 1) - mid_diff
mid_ceil = mid_floor + (odd + 1) % 2
return make_timeseries(
self.tstamps, (self._ts['values'][ordered][mid_floor] +
self._ts['values'][ordered][mid_ceil]) / 2.0)
示例14: encode_2bit_base
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def encode_2bit_base(values):
"""Generic encoder for data stored using two bits.
This returns an unsigned integer array containing encoded sample
values that range from 0 to 3. The conversion from floating point
sample value to unsigned int is given below, with
``lv = TWO_BIT_1_SIGMA = 2.1745``:
================= ======
Input range Output
================= ======
value < -lv 0
-lv < value < 0. 2
0. < value < lv 1
lv < value 3
================= ======
This does not pack the samples into bytes.
"""
# Optimized for speed by doing calculations in-place, and ensuring that
# the dtypes match.
values = np.clip(values, clip_low, clip_high)
values += two_bit_2_sigma
bitvalues = np.empty(values.shape, np.uint8)
return np.floor_divide(values, TWO_BIT_1_SIGMA, out=bitvalues,
casting='unsafe')
示例15: test_floor_division_complex
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import floor_divide [as 别名]
def test_floor_division_complex(self):
# check that implementation is correct
msg = "Complex floor division implementation check"
x = np.array([.9 + 1j, -.1 + 1j, .9 + .5*1j, .9 + 2.*1j], dtype=np.complex128)
y = np.array([0., -1., 0., 0.], dtype=np.complex128)
assert_equal(np.floor_divide(x**2, x), y, err_msg=msg)
# check overflow, underflow
msg = "Complex floor division overflow/underflow check"
x = np.array([1.e+110, 1.e-110], dtype=np.complex128)
y = np.floor_divide(x**2, x)
assert_equal(y, [1.e+110, 0], err_msg=msg)