本文整理汇总了Python中scipy.ndimage.mean方法的典型用法代码示例。如果您正苦于以下问题:Python ndimage.mean方法的具体用法?Python ndimage.mean怎么用?Python ndimage.mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scipy.ndimage
的用法示例。
在下文中一共展示了ndimage.mean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: labelmeanfilter_nd
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def labelmeanfilter_nd(y, x):
# requires integer labels
# from mailing list scipy-user 2009-02-11
# adjusted for 2d x with column variables
labelsunique = np.arange(np.max(y)+1)
labmeansdata = []
labmeans = []
for xx in x.T:
labelmeans = np.array(ndimage.mean(xx, labels=y, index=labelsunique))
labmeansdata.append(labelmeans[y])
labmeans.append(labelmeans)
# group count:
labelcount = np.array(ndimage.histogram(y, labelsunique[0], labelsunique[-1]+1,
1, labels=y, index=labelsunique))
# returns array of lable/group counts and of label/group means
# and label/group means for each original observation
return labelcount, np.array(labmeans), np.array(labmeansdata).T
示例2: test_stat_funcs_2d
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_stat_funcs_2d():
"""Apply the stat funcs to a 2-d array."""
a = np.array([[5,6,0,0,0], [8,9,0,0,0], [0,0,0,3,5]])
lbl = np.array([[1,1,0,0,0], [1,1,0,0,0], [0,0,0,2,2]])
mean = ndimage.mean(a, labels=lbl, index=[1, 2])
assert_array_equal(mean, [7.0, 4.0])
var = ndimage.variance(a, labels=lbl, index=[1, 2])
assert_array_equal(var, [2.5, 1.0])
std = ndimage.standard_deviation(a, labels=lbl, index=[1, 2])
assert_array_almost_equal(std, np.sqrt([2.5, 1.0]))
med = ndimage.median(a, labels=lbl, index=[1, 2])
assert_array_equal(med, [7.0, 4.0])
min = ndimage.minimum(a, labels=lbl, index=[1, 2])
assert_array_equal(min, [5, 3])
max = ndimage.maximum(a, labels=lbl, index=[1, 2])
assert_array_equal(max, [9, 5])
示例3: apply
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def apply(self):
sc = self.scene
org = self.original
factor = self.factor
sx, sy = sc.displacement.shape
gx, gy = num.ogrid[0:sx, 0:sy]
regions = sy/factor * (gx/factor) + gy/factor
indices = num.arange(regions.max() + 1)
def block_downsample(arr):
res = ndimage.mean(
arr,
labels=regions,
index=indices)
res.shape = (sx/factor, sy/factor)
return res
sc.displacement = block_downsample(sc.displacement)
sc.theta = block_downsample(sc.theta)
sc.phi = block_downsample(sc.phi)
sc.frame.dLat = org['frame.dLat'] * self.factor
sc.frame.dLon = org['frame.dLat'] * self.factor
示例4: test_stat_funcs_2d
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_stat_funcs_2d():
a = np.array([[5,6,0,0,0], [8,9,0,0,0], [0,0,0,3,5]])
lbl = np.array([[1,1,0,0,0], [1,1,0,0,0], [0,0,0,2,2]])
mean = ndimage.mean(a, labels=lbl, index=[1, 2])
assert_array_equal(mean, [7.0, 4.0])
var = ndimage.variance(a, labels=lbl, index=[1, 2])
assert_array_equal(var, [2.5, 1.0])
std = ndimage.standard_deviation(a, labels=lbl, index=[1, 2])
assert_array_almost_equal(std, np.sqrt([2.5, 1.0]))
med = ndimage.median(a, labels=lbl, index=[1, 2])
assert_array_equal(med, [7.0, 4.0])
min = ndimage.minimum(a, labels=lbl, index=[1, 2])
assert_array_equal(min, [5, 3])
max = ndimage.maximum(a, labels=lbl, index=[1, 2])
assert_array_equal(max, [9, 5])
示例5: labelmeanfilter
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def labelmeanfilter(y, x):
# requires integer labels
# from mailing list scipy-user 2009-02-11
labelsunique = np.arange(np.max(y)+1)
labelmeans = np.array(ndimage.mean(x, labels=y, index=labelsunique))
# returns label means for each original observation
return labelmeans[y]
#groupcount: i.e. number of observation by group/label
#np.array(ndimage.histogram(yrvs[:,0],0,10,1,labels=yrvs[:,0],index=np.unique(yrvs[:,0])))
示例6: labelmeanfilter_str
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def labelmeanfilter_str(ys, x):
# works also for string labels in ys, but requires 1D
# from mailing list scipy-user 2009-02-11
unil, unilinv = np.unique(ys, return_index=False, return_inverse=True)
labelmeans = np.array(ndimage.mean(x, labels=unilinv, index=np.arange(np.max(unil)+1)))
arr3 = labelmeans[unilinv]
return arr3
示例7: groupsstats_1d
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def groupsstats_1d(y, x, labelsunique):
'''use ndimage to get fast mean and variance'''
labelmeans = np.array(ndimage.mean(x, labels=y, index=labelsunique))
labelvars = np.array(ndimage.var(x, labels=y, index=labelsunique))
return labelmeans, labelvars
示例8: groupsstats_dummy
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def groupsstats_dummy(y, x, nonseq=0):
if x.ndim == 1:
# use groupsstats_1d
x = x[:,np.newaxis]
dummy = cat2dummy(y, nonseq=nonseq)
countgr = dummy.sum(0, dtype=float)
meangr = np.dot(x.T,dummy)/countgr
meandata = np.dot(dummy,meangr.T) # category/group means as array in shape of x
xdevmeangr = x - meandata # deviation from category/group mean
vargr = np.dot((xdevmeangr * xdevmeangr).T, dummy) / countgr
return meangr, vargr, xdevmeangr, countgr
示例9: test_mean01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean01():
"mean 1"
labels = np.array([1, 0], bool)
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.mean(input, labels=labels)
assert_almost_equal(output, 2.0)
示例10: test_mean02
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean02():
"mean 2"
labels = np.array([1, 0], bool)
input = np.array([[1, 2], [3, 4]], bool)
output = ndimage.mean(input, labels=labels)
assert_almost_equal(output, 1.0)
示例11: test_mean03
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean03():
"mean 3"
labels = np.array([1, 2])
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.mean(input, labels=labels,
index=2)
assert_almost_equal(output, 3.0)
示例12: test_mean04
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean04():
"mean 4"
labels = np.array([[1, 2], [2, 4]], np.int8)
olderr = np.seterr(all='ignore')
try:
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.mean(input, labels=labels,
index=[4, 8, 2])
assert_array_almost_equal(output[[0,2]], [4.0, 2.5])
assert_(np.isnan(output[1]))
finally:
np.seterr(**olderr)
示例13: test_mean01
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean01():
labels = np.array([1, 0], bool)
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.mean(input, labels=labels)
assert_almost_equal(output, 2.0)
示例14: test_mean02
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean02():
labels = np.array([1, 0], bool)
input = np.array([[1, 2], [3, 4]], bool)
output = ndimage.mean(input, labels=labels)
assert_almost_equal(output, 1.0)
示例15: test_mean03
# 需要导入模块: from scipy import ndimage [as 别名]
# 或者: from scipy.ndimage import mean [as 别名]
def test_mean03():
labels = np.array([1, 2])
for type in types:
input = np.array([[1, 2], [3, 4]], type)
output = ndimage.mean(input, labels=labels,
index=2)
assert_almost_equal(output, 3.0)