本文整理汇总了Python中numpy.ma.zeros方法的典型用法代码示例。如果您正苦于以下问题:Python ma.zeros方法的具体用法?Python ma.zeros怎么用?Python ma.zeros使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.ma
的用法示例。
在下文中一共展示了ma.zeros方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: empty
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def empty(self, process_tile):
"""
Return empty data.
Parameters
----------
process_tile : ``BufferedTile``
must be member of process ``TilePyramid``
Returns
-------
empty data : array
empty array with data type given in output parameters
"""
bands = (
self.output_params["bands"]
if "bands" in self.output_params
else PNG_DEFAULT_PROFILE["count"]
)
return ma.masked_array(
data=ma.zeros((bands, ) + process_tile.shape),
mask=ma.zeros((bands, ) + process_tile.shape),
dtype=PNG_DEFAULT_PROFILE["dtype"]
)
示例2: comp_g
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def comp_g(dert__, odd):
g__ = dert__[0]
a__ = dert__[1:]
# loop through each pair of comparands in a kernel
dgy__ = ma.zeros(np.subtract(g.shape, rng))
dgx__ = ma.zeros(np.subtract(g.shape, rng))
for x_coeff, y_coeff, (ts, _ts) in zip(X_COEFFS[rng],
Y_COEFFS[rng],
TRANSLATING_SLICES_PAIRS_[rng]):
# find angle differences
da__ = angle_diff(a__[ts], a__[_ts])
# compute dg: dg = g - _g * cos(da) at each position
dg__ = g__[ts] - g__[_ts] * da__[1]
# accumulate dgy, dgx
dgx__ += dg__ * x_coeff
dgy__ += dg__ * y_coeff
gg__ = ma.hypot(dgy__, dgx__)
return ma.stack((g__, gg__, dgy__, dgx__))
示例3: test_repack_fields
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def test_repack_fields(self):
dt = np.dtype('u1,f4,i8', align=True)
a = np.zeros(2, dtype=dt)
assert_equal(repack_fields(dt), np.dtype('u1,f4,i8'))
assert_equal(repack_fields(a).itemsize, 13)
assert_equal(repack_fields(repack_fields(dt), align=True), dt)
# make sure type is preserved
dt = np.dtype((np.record, dt))
assert_(repack_fields(dt).type is np.record)
示例4: test_simple_flexible
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def test_simple_flexible(self):
# Test recursive_fill_fields on flexible-array
a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)])
b = np.zeros((3,), dtype=a.dtype)
test = recursive_fill_fields(a, b)
control = np.array([(1, 10.), (2, 20.), (0, 0.)],
dtype=[('A', int), ('B', float)])
assert_equal(test, control)
示例5: test_masked_flexible
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def test_masked_flexible(self):
# Test recursive_fill_fields on masked flexible-array
a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)],
dtype=[('A', int), ('B', float)])
b = ma.zeros((3,), dtype=a.dtype)
test = recursive_fill_fields(a, b)
control = ma.array([(1, 10.), (2, 20.), (0, 0.)],
mask=[(0, 1), (1, 0), (0, 0)],
dtype=[('A', int), ('B', float)])
assert_equal(test, control)
示例6: test_different_field_order
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def test_different_field_order(self):
# gh-8940
a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')])
b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')])
# this should not give a FutureWarning:
j = join_by(['c', 'b'], a, b, jointype='inner', usemask=False)
assert_equal(j.dtype.names, ['b', 'c', 'a1', 'a2'])
示例7: test_duplicate_keys
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def test_duplicate_keys(self):
a = np.zeros(3, dtype=[('a', 'i4'), ('b', 'f4'), ('c', 'u1')])
b = np.ones(3, dtype=[('c', 'u1'), ('b', 'f4'), ('a', 'i4')])
assert_raises(ValueError, join_by, ['a', 'b', 'b'], a, b)
示例8: test_simple_flexible
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def test_simple_flexible(self):
"Test recursive_fill_fields on flexible-array"
a = np.array([(1, 10.), (2, 20.)], dtype=[('A', int), ('B', float)])
b = np.zeros((3,), dtype=a.dtype)
test = recursive_fill_fields(a, b)
control = np.array([(1, 10.), (2, 20.), (0, 0.)],
dtype=[('A', int), ('B', float)])
assert_equal(test, control)
#
示例9: test_masked_flexible
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def test_masked_flexible(self):
"Test recursive_fill_fields on masked flexible-array"
a = ma.array([(1, 10.), (2, 20.)], mask=[(0, 1), (1, 0)],
dtype=[('A', int), ('B', float)])
b = ma.zeros((3,), dtype=a.dtype)
test = recursive_fill_fields(a, b)
control = ma.array([(1, 10.), (2, 20.), (0, 0.)],
mask=[(0, 1), (1, 0), (0, 0)],
dtype=[('A', int), ('B', float)])
assert_equal(test, control)
#
示例10: _draw_steps_pre
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def _draw_steps_pre(self, renderer, gc, path, trans):
vertices = self._xy
steps = ma.zeros((2 * len(vertices) - 1, 2), np.float_)
steps[0::2, 0], steps[1::2, 0] = vertices[:, 0], vertices[:-1, 0]
steps[0::2, 1], steps[1:-1:2, 1] = vertices[:, 1], vertices[1:, 1]
path = Path(steps)
path = path.transformed(self.get_transform())
self._lineFunc(renderer, gc, path, IdentityTransform())
示例11: _draw_steps_post
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def _draw_steps_post(self, renderer, gc, path, trans):
vertices = self._xy
steps = ma.zeros((2 * len(vertices) - 1, 2), np.float_)
steps[::2, 0], steps[1:-1:2, 0] = vertices[:, 0], vertices[1:, 0]
steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:-1, 1]
path = Path(steps)
path = path.transformed(self.get_transform())
self._lineFunc(renderer, gc, path, IdentityTransform())
示例12: _draw_steps_mid
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import zeros [as 别名]
def _draw_steps_mid(self, renderer, gc, path, trans):
vertices = self._xy
steps = ma.zeros((2 * len(vertices), 2), np.float_)
steps[1:-1:2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0])
steps[2::2, 0] = 0.5 * (vertices[:-1, 0] + vertices[1:, 0])
steps[0, 0] = vertices[0, 0]
steps[-1, 0] = vertices[-1, 0]
steps[0::2, 1], steps[1::2, 1] = vertices[:, 1], vertices[:, 1]
path = Path(steps)
path = path.transformed(self.get_transform())
self._lineFunc(renderer, gc, path, IdentityTransform())