本文整理汇总了Python中numpy.ma.sqrt方法的典型用法代码示例。如果您正苦于以下问题:Python ma.sqrt方法的具体用法?Python ma.sqrt怎么用?Python ma.sqrt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy.ma
的用法示例。
在下文中一共展示了ma.sqrt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pointbiserialr
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def pointbiserialr(x, y):
x = ma.fix_invalid(x, copy=True).astype(bool)
y = ma.fix_invalid(y, copy=True).astype(float)
# Get rid of the missing data ..........
m = ma.mask_or(ma.getmask(x), ma.getmask(y))
if m is not nomask:
unmask = np.logical_not(m)
x = x[unmask]
y = y[unmask]
#
n = len(x)
# phat is the fraction of x values that are True
phat = x.sum() / float(n)
y0 = y[~x] # y-values where x is False
y1 = y[x] # y-values where x is True
y0m = y0.mean()
y1m = y1.mean()
#
rpb = (y1m - y0m)*np.sqrt(phat * (1-phat)) / y.std()
#
df = n-2
t = rpb*ma.sqrt(df/(1.0-rpb**2))
prob = betai(0.5*df, 0.5, df/(df+t*t))
return rpb, prob
示例2: skew
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def skew(a, axis=0, bias=True):
a, axis = _chk_asarray(a,axis)
n = a.count(axis)
m2 = moment(a, 2, axis)
m3 = moment(a, 3, axis)
olderr = np.seterr(all='ignore')
try:
vals = ma.where(m2 == 0, 0, m3 / m2**1.5)
finally:
np.seterr(**olderr)
if not bias:
can_correct = (n > 2) & (m2 > 0)
if can_correct.any():
m2 = np.extract(can_correct, m2)
m3 = np.extract(can_correct, m3)
nval = ma.sqrt((n-1.0)*n)/(n-2.0)*m3/m2**1.5
np.place(vals, can_correct, nval)
return vals
示例3: kurtosistest
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def kurtosistest(a, axis=0):
a, axis = _chk_asarray(a, axis)
n = a.count(axis=axis).astype(float)
if np.min(n) < 20:
warnings.warn(
"kurtosistest only valid for n>=20 ... continuing anyway, n=%i" %
np.min(n))
b2 = kurtosis(a, axis, fisher=False)
E = 3.0*(n-1) / (n+1)
varb2 = 24.0*n*(n-2)*(n-3) / ((n+1)*(n+1)*(n+3)*(n+5))
x = (b2-E)/ma.sqrt(varb2)
sqrtbeta1 = 6.0*(n*n-5*n+2)/((n+7)*(n+9)) * np.sqrt((6.0*(n+3)*(n+5)) /
(n*(n-2)*(n-3)))
A = 6.0 + 8.0/sqrtbeta1 * (2.0/sqrtbeta1 + np.sqrt(1+4.0/(sqrtbeta1**2)))
term1 = 1 - 2./(9.0*A)
denom = 1 + x*ma.sqrt(2/(A-4.0))
denom[denom < 0] = masked
term2 = ma.power((1-2.0/A)/denom,1/3.0)
Z = (term1 - term2) / np.sqrt(2/(9.0*A))
return Z, (1.0-stats.zprob(Z))*2
示例4: f_value_wilks_lambda
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def f_value_wilks_lambda(ER, EF, dfnum, dfden, a, b):
"""Calculation of Wilks lambda F-statistic for multivariate data, per
Maxwell & Delaney p.657.
"""
ER = ma.array(ER, copy=False, ndmin=2)
EF = ma.array(EF, copy=False, ndmin=2)
if ma.getmask(ER).any() or ma.getmask(EF).any():
raise NotImplementedError("Not implemented when the inputs "
"have missing data")
lmbda = np.linalg.det(EF) / np.linalg.det(ER)
q = ma.sqrt(((a-1)**2*(b-1)**2 - 2) / ((a-1)**2 + (b-1)**2 - 5))
q = ma.filled(q, 1)
n_um = (1 - lmbda**(1.0/q))*(a-1)*(b-1)
d_en = lmbda**(1.0/q) / (n_um*q - 0.5*(a-1)*(b-1) + 1)
return n_um / d_en
示例5: stde_median
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def stde_median(data, axis=None):
"""Returns the McKean-Schrader estimate of the standard error of the sample
median along the given axis. masked values are discarded.
Parameters
----------
data : ndarray
Data to trim.
axis : {None,int}, optional
Axis along which to perform the trimming.
If None, the input array is first flattened.
"""
def _stdemed_1D(data):
data = np.sort(data.compressed())
n = len(data)
z = 2.5758293035489004
k = int(np.round((n+1)/2. - z * np.sqrt(n/4.),0))
return ((data[n-k] - data[k-1])/(2.*z))
data = ma.array(data, copy=False, subok=True)
if (axis is None):
return _stdemed_1D(data)
else:
if data.ndim > 2:
raise ValueError("Array 'data' must be at most two dimensional, "
"but got data.ndim = %d" % data.ndim)
return ma.apply_along_axis(_stdemed_1D, axis, data)
示例6: compare_medians_ms
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def compare_medians_ms(group_1, group_2, axis=None):
"""
Compares the medians from two independent groups along the given axis.
The comparison is performed using the McKean-Schrader estimate of the
standard error of the medians.
Parameters
----------
group_1 : array_like
First dataset. Has to be of size >=7.
group_2 : array_like
Second dataset. Has to be of size >=7.
axis : int, optional
Axis along which the medians are estimated. If None, the arrays are
flattened. If `axis` is not None, then `group_1` and `group_2`
should have the same shape.
Returns
-------
compare_medians_ms : {float, ndarray}
If `axis` is None, then returns a float, otherwise returns a 1-D
ndarray of floats with a length equal to the length of `group_1`
along `axis`.
"""
(med_1, med_2) = (ma.median(group_1,axis=axis), ma.median(group_2,axis=axis))
(std_1, std_2) = (mstats.stde_median(group_1, axis=axis),
mstats.stde_median(group_2, axis=axis))
W = np.abs(med_1 - med_2) / ma.sqrt(std_1**2 + std_2**2)
return 1 - norm.cdf(W)
示例7: linregress
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def linregress(*args):
if len(args) == 1: # more than 1D array?
args = ma.array(args[0], copy=True)
if len(args) == 2:
x = args[0]
y = args[1]
else:
x = args[:,0]
y = args[:,1]
else:
x = ma.array(args[0]).flatten()
y = ma.array(args[1]).flatten()
m = ma.mask_or(ma.getmask(x), ma.getmask(y))
if m is not nomask:
x = ma.array(x,mask=m)
y = ma.array(y,mask=m)
n = len(x)
(xmean, ymean) = (x.mean(), y.mean())
(xm, ym) = (x-xmean, y-ymean)
(Sxx, Syy) = (ma.add.reduce(xm*xm), ma.add.reduce(ym*ym))
Sxy = ma.add.reduce(xm*ym)
r_den = ma.sqrt(Sxx*Syy)
if r_den == 0.0:
r = 0.0
else:
r = Sxy / r_den
if (r > 1.0):
r = 1.0 # from numerical error
# z = 0.5*log((1.0+r+TINY)/(1.0-r+TINY))
df = n-2
t = r * ma.sqrt(df/(1.0-r*r))
prob = betai(0.5*df,0.5,df/(df+t*t))
slope = Sxy / Sxx
intercept = ymean - slope*xmean
sterrest = ma.sqrt(1.-r*r) * y.std()
return slope, intercept, r, prob, sterrest
示例8: ttest_onesamp
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def ttest_onesamp(a, popmean):
a = ma.asarray(a)
x = a.mean(axis=None)
v = a.var(axis=None,ddof=1)
n = a.count(axis=None)
df = n-1
svar = ((n-1)*v) / float(df)
t = (x-popmean)/ma.sqrt(svar*(1.0/n))
prob = betai(0.5*df,0.5,df/(df+t*t))
return t,prob
示例9: ttest_ind
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def ttest_ind(a, b, axis=0):
a, b, axis = _chk2_asarray(a, b, axis)
(x1, x2) = (a.mean(axis), b.mean(axis))
(v1, v2) = (a.var(axis=axis, ddof=1), b.var(axis=axis, ddof=1))
(n1, n2) = (a.count(axis), b.count(axis))
df = n1+n2-2
svar = ((n1-1)*v1+(n2-1)*v2) / float(df)
svar == 0
t = (x1-x2)/ma.sqrt(svar*(1.0/n1 + 1.0/n2)) # N-D COMPUTATION HERE!!!!!!
t = ma.filled(t, 1) # replace NaN t-values with 1.0
probs = betai(0.5*df,0.5,float(df)/(df+t*t)).reshape(t.shape)
return t, probs.squeeze()
示例10: tsem
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def tsem(a, limits=None, inclusive=(True,True)):
a = ma.asarray(a).ravel()
if limits is None:
n = float(a.count())
return a.std()/ma.sqrt(n)
am = trima(a.ravel(), limits, inclusive)
sd = np.sqrt(am.var())
return sd / am.count()
示例11: stde_median
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def stde_median(data, axis=None):
"""Returns the McKean-Schrader estimate of the standard error of the sample
median along the given axis. masked values are discarded.
Parameters
----------
data : ndarray
Data to trim.
axis : {None,int}, optional
Axis along which to perform the trimming.
If None, the input array is first flattened.
"""
def _stdemed_1D(data):
data = np.sort(data.compressed())
n = len(data)
z = 2.5758293035489004
k = int(np.round((n+1)/2. - z * np.sqrt(n/4.),0))
return ((data[n-k] - data[k-1])/(2.*z))
#
data = ma.array(data, copy=False, subok=True)
if (axis is None):
return _stdemed_1D(data)
else:
if data.ndim > 2:
raise ValueError("Array 'data' must be at most two dimensional, but got data.ndim = %d" % data.ndim)
return ma.apply_along_axis(_stdemed_1D, axis, data)
#####--------------------------------------------------------------------------
#---- --- Normality Tests ---
#####--------------------------------------------------------------------------
示例12: sem
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def sem(a, axis=0):
a, axis = _chk_asarray(a, axis)
n = a.count(axis=axis)
s = a.std(axis=axis,ddof=0) / ma.sqrt(n-1)
return s
示例13: f_value_wilks_lambda
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def f_value_wilks_lambda(ER, EF, dfnum, dfden, a, b):
"""Calculation of Wilks lambda F-statistic for multivarite data, per
Maxwell & Delaney p.657.
"""
ER = ma.array(ER, copy=False, ndmin=2)
EF = ma.array(EF, copy=False, ndmin=2)
if ma.getmask(ER).any() or ma.getmask(EF).any():
raise NotImplementedError("Not implemented when the inputs "
"have missing data")
lmbda = np.linalg.det(EF) / np.linalg.det(ER)
q = ma.sqrt(((a-1)**2*(b-1)**2 - 2) / ((a-1)**2 + (b-1)**2 - 5))
q = ma.filled(q, 1)
n_um = (1 - lmbda**(1.0/q))*(a-1)*(b-1)
d_en = lmbda**(1.0/q) / (n_um*q - 0.5*(a-1)*(b-1) + 1)
return n_um / d_en
示例14: vector_sum
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def vector_sum(x_arr, y_arr):
"""
Calculate the vector sum of arrays of
x and y vectors.
:param x_arr: array of x-directed vectors
:type x_arr: numpy.array
:param y_arr: array of y-directed vectors
:type y_arr: numpy.array
:return: array of vector sums
:rtype: numpy.array
"""
return ma.sqrt(x_arr**2 + y_arr**2)
示例15: cart2polar
# 需要导入模块: from numpy import ma [as 别名]
# 或者: from numpy.ma import sqrt [as 别名]
def cart2polar(x, y, degrees=True):
"""
Convert cartesian X and Y to polar RHO and THETA.
:param x: x cartesian coordinate
:param y: y cartesian coordinate
:param degrees: True = return theta in degrees, False = return theta in
radians. [default: True]
:return: r, theta
"""
rho = ma.sqrt(x ** 2 + y ** 2)
theta = ma.arctan2(y, x)
if degrees:
theta *= (180 / math.pi)
return rho, theta