本文整理汇总了Python中numpy.ma.allclose方法的典型用法代码示例。如果您正苦于以下问题:Python ma.allclose方法的具体用法?Python ma.allclose怎么用?Python ma.allclose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.ma
的用法示例。
在下文中一共展示了ma.allclose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: obrientransform
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import allclose [as 别名]
def obrientransform(*args):
"""
Computes a transform on input data (any number of columns). Used to
test for homogeneity of variance prior to running one-way stats. Each
array in ``*args`` is one level of a factor. If an `f_oneway()` run on
the transformed data and found significant, variances are unequal. From
Maxwell and Delaney, p.112.
Returns: transformed data for use in an ANOVA
"""
data = argstoarray(*args).T
v = data.var(axis=0,ddof=1)
m = data.mean(0)
n = data.count(0).astype(float)
# result = ((N-1.5)*N*(a-m)**2 - 0.5*v*(n-1))/((n-1)*(n-2))
data -= m
data **= 2
data *= (n-1.5)*n
data -= 0.5*v*(n-1)
data /= (n-1.)*(n-2.)
if not ma.allclose(v,data.mean(0)):
raise ValueError("Lack of convergence in obrientransform.")
return data
示例2: obrientransform
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import allclose [as 别名]
def obrientransform(*args):
"""
Computes a transform on input data (any number of columns). Used to
test for homogeneity of variance prior to running one-way stats. Each
array in *args is one level of a factor. If an F_oneway() run on the
transformed data and found significant, variances are unequal. From
Maxwell and Delaney, p.112.
Returns: transformed data for use in an ANOVA
"""
data = argstoarray(*args).T
v = data.var(axis=0,ddof=1)
m = data.mean(0)
n = data.count(0).astype(float)
# result = ((N-1.5)*N*(a-m)**2 - 0.5*v*(n-1))/((n-1)*(n-2))
data -= m
data **= 2
data *= (n-1.5)*n
data -= 0.5*v*(n-1)
data /= (n-1.)*(n-2.)
if not ma.allclose(v,data.mean(0)):
raise ValueError("Lack of convergence in obrientransform.")
return data
示例3: test_processing
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import allclose [as 别名]
def test_processing(mp_tmpdir, cleantopo_br, cleantopo_tl):
"""Test correct processing (read and write) outputs."""
for cleantopo_process in [cleantopo_br.path, cleantopo_tl.path]:
with mapchete.open(cleantopo_process) as mp:
for zoom in range(6):
tiles = []
for tile in mp.get_process_tiles(zoom):
output = mp.execute(tile)
tiles.append((tile, output))
assert isinstance(output, ma.MaskedArray)
assert output.shape == output.shape
assert not ma.all(output.mask)
mp.write(tile, output)
mosaic = create_mosaic(tiles)
try:
temp_vrt = os.path.join(mp_tmpdir, str(zoom)+".vrt")
gdalbuildvrt = "gdalbuildvrt %s %s/%s/*/*.tif > /dev/null" % (
temp_vrt, mp.config.output.path, zoom)
os.system(gdalbuildvrt)
with rasterio.open(temp_vrt, "r") as testfile:
for file_item, mosaic_item in zip(
testfile.meta["transform"], mosaic.affine
):
assert file_item == mosaic_item
band = testfile.read(1, masked=True)
assert band.shape == mosaic.data.shape
assert ma.allclose(band, mosaic.data)
assert ma.allclose(band.mask, mosaic.data.mask)
finally:
shutil.rmtree(mp_tmpdir, ignore_errors=True)