All Samples(6047) | Call(5597) | Derive(0) | Import(450)
sqrt(x[, out])
Return the positive square-root of an array, element-wise.
Parameters
----------
x : array_like
The values whose square-roots are required.
out : ndarray, optional
Alternate array object in which to put the result; if provided, it
must have the same shape as `x`
Returns
-------
y : ndarray
An array of the same shape as `x`, containing the positive
square-root of each element in `x`. If any element in `x` is
complex, a complex array is returned (and the square-roots of
negative reals are calculated). If all of the elements in `x`
are real, so is `y`, with negative elements returning ``nan``.
If `out` was provided, `y` is a reference to it.
See Also
--------
lib.scimath.sqrt
A version which returns complex numbers when given negative reals.
Notes
-----
*sqrt* has--consistent with common convention--as its branch cut the
real "interval" [`-inf`, 0), and is continuous from above on it.
(A branch cut is a curve in the complex plane across which a given
complex function fails to be continuous.)
Examples
--------
>>> np.sqrt([1,4,9])
array([ 1., 2., 3.])
>>> np.sqrt([4, -1, -3+4J])
array([ 2.+0.j, 0.+1.j, 1.+2.j])
>>> np.sqrt([4, -1, numpy.inf])
array([ 2., NaN, Inf])src/a/u/aureservoir-HEAD/python/examples/filtering.py aureservoir(Download)
Afilt[1] = -2*N.cos(w0) Afilt[2] = 1 - alpha/A elif( ftype=='lowShelf' ): Bfilt[0] = A*((A+1)-(A-1)*N.cos(w0) + 2*N.sqrt(A)*alpha) Bfilt[1] = 2*A*( (A-1) - (A+1)*N.cos(w0) ) Bfilt[2] = A*((A+1)-(A-1)*N.cos(w0)-2*N.sqrt(A)*alpha) Afilt[0] = (A+1)+(A-1)*N.cos(w0)+2*N.sqrt(A)*alpha Afilt[1] = -2*( (A-1) + (A+1)*N.cos(w0)) Afilt[2] = (A+1) + (A-1)*N.cos(w0)-2*N.sqrt(A)*alpha elif( ftype=='highShelf' ): Bfilt[0] = A*((A+1)+(A-1)*N.cos(w0)+2*N.sqrt(A)*alpha) Bfilt[1] = -2*A*( (A-1) + (A+1)*N.cos(w0) ) Bfilt[2] = A*( (A+1) + (A-1)*N.cos(w0)-2*N.sqrt(A)*alpha ) Afilt[0] = (A+1) - (A-1)*N.cos(w0) + 2*N.sqrt(A)*alpha
Bfilt[2] = A*( (A+1) + (A-1)*N.cos(w0)-2*N.sqrt(A)*alpha ) Afilt[0] = (A+1) - (A-1)*N.cos(w0) + 2*N.sqrt(A)*alpha Afilt[1] = 2*( (A-1) - (A+1)*N.cos(w0) ) Afilt[2] = (A+1) - (A-1)*N.cos(w0) - 2*N.sqrt(A)*alpha else: raise ValueError, "Wrong filter type !"
# calculate gain factor gain = abs( (-2*N.exp(4*1j*cf*N.pi*T)*T + \ 2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \ (N.cos(2*cf*N.pi*T) - N.sqrt(3. - 2**(3./2.)) * \ N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \ 2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \ (N.cos(2*cf*N.pi*T) + N.sqrt(3. - 2**(3./2.)) * \ N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \ 2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) - \ N.sqrt(3. + 2**(3./2.)) * N.sin(2*cf*N.pi*T))) * \ (-2*N.exp(4*1j*cf*N.pi*T)*T + 2*N.exp(-(B*T) + \ 2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) + \ N.sqrt(3. + 2**(3./2.)) * N.sin(2*cf*N.pi*T))) / \
# calculate gain factor gain = abs( (-2*N.exp(4*1j*cf*N.pi*T)*T + \ 2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \ (N.cos(2*cf*N.pi*T) - N.sqrt(3. - 2**(3./2.)) * \ N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \ 2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * \ (N.cos(2*cf*N.pi*T) + N.sqrt(3. - 2**(3./2.)) * \ N.sin(2*cf*N.pi*T))) * (-2*N.exp(4*1j*cf*N.pi*T)*T + \ 2*N.exp(-(B*T) + 2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) - \ N.sqrt(3. + 2**(3./2.)) * N.sin(2*cf*N.pi*T))) * \ (-2*N.exp(4*1j*cf*N.pi*T)*T + 2*N.exp(-(B*T) + \ 2*1j*cf*N.pi*T) * T * (N.cos(2*cf*N.pi*T) + \ N.sqrt(3. + 2**(3./2.)) * N.sin(2*cf*N.pi*T))) / \
# init the rest tmp = 2*T*N.cos(2*cf*N.pi*T) / N.exp(B*T) Bfilt[:,0,1] = -(tmp+2*N.sqrt(3.+2**1.5)*T*N.sin(2*cf*N.pi*T)/N.exp(B*T))/2. Bfilt[:,1,1] = -(tmp-2*N.sqrt(3.+2**1.5)*T*N.sin(2*cf*N.pi*T)/N.exp(B*T))/2. Bfilt[:,2,1] = -(tmp+2*N.sqrt(3.-2**1.5)*T*N.sin(2*cf*N.pi*T)/N.exp(B*T))/2. Bfilt[:,3,1] = -(tmp-2*N.sqrt(3.-2**1.5)*T*N.sin(2*cf*N.pi*T)/N.exp(B*T))/2.
src/p/y/pyfusion-HEAD/examples/test_savez.py pyfusion(Download)
# debug_save_compress=False;
global verbose
from numpy import savez, array, arange, remainder, mod, sin, pi, min, max, \
size, diff, random, mean, unique, sort, sqrt, float32
from time import time
from pylab import plot, show
# remain is relative to unit step, need to scale back down
maxerr=max(abs(remain))*deltar
# not clear what the max expected error is - small for 12 bits, gets larger quicly
if maxerr<eps*sqrt(yspan): print("appears to be successful")
print('maximum error with %g noise = %g, =%.3g x eps' % (eps,maxerr,maxerr/eps))
#
src/n/i/nipy-HEAD/examples/fiac/fiac_example.py nipy(Download)
fixed_var += ivar
# Now, compute the fixed effects variance and t statistic
fixed_sd = np.sqrt(fixed_var)
isd = np.nan_to_num(1. / fixed_sd)
fixed_t = fixed_effect * isd
coordmap = futil.load_image_fiac("fiac_00","wanatomical.nii").coordmap
adjusted_var = sd**2 + random_var
adjusted_sd = np.sqrt(adjusted_var)
results = onesample.estimate_mean(Y, adjusted_sd)
for n in ['effect', 'sd', 't']:
random_var = varest['random']
adjusted_var = sd**2 + random_var
adjusted_sd = np.sqrt(adjusted_var)
results = onesample.estimate_mean(Y, adjusted_sd)
T = results['t']
src/n/i/NiPy-OLD-HEAD/examples/fiac/fiac_example.py NiPy-OLD(Download)
fixed_var += ivar
# Now, compute the fixed effects variance and t statistic
fixed_sd = np.sqrt(fixed_var)
isd = np.nan_to_num(1. / fixed_sd)
fixed_t = fixed_effect * isd
coordmap = futil.load_image_fiac("fiac_00","wanatomical.nii").coordmap
adjusted_var = sd**2 + random_var
adjusted_sd = np.sqrt(adjusted_var)
results = onesample.estimate_mean(Y, adjusted_sd)
for n in ['effect', 'sd', 't']:
random_var = varest['random']
adjusted_var = sd**2 + random_var
adjusted_sd = np.sqrt(adjusted_var)
results = onesample.estimate_mean(Y, adjusted_sd)
T = results['t']
src/n/i/nipy-HEAD/nipy/algorithms/statistics/tests/test_onesample.py nipy(Download)
) + np.ones((40,ntrial))
for i in range(n):
Y = np.random.standard_normal((40,ntrial)) * np.sqrt((sd**2 + sigma2))
results = onesample.estimate_varatio(Y, sd)
results = onesample.estimate_varatio(Y, sd)
random[i] = results['random'].mean()
rsd[i] = results['random'].std()
# Compute the mean just to be sure it works
W = 1. / (sd**2 + results['random'])
mu = onesample.estimate_mean(Y, np.sqrt(sd**2 + results['random']))['effect']
mu = onesample.estimate_mean(Y, np.sqrt(sd**2 + results['random']))['effect']
yield assert_almost_equal, mu, (W*Y).sum(0) / W.sum(0)
rsd = np.sqrt((rsd**2).mean() / ntrial)
T = np.fabs((random.mean() - sigma2) / (rsd / np.sqrt(n)))
# should fail one in every 1/p trials at least for sigma > 0,
src/n/i/nipy-HEAD/nipy/neurospin/group/spatial_relaxation_onesample.py nipy(Download)
if update_spatial:
#B = len(self.D.block)
self.std = np.sqrt(
(self.S4 + 2 * self.std_scale) / (self.D.U.size + 2 * self.std_shape + 2))
self.v = (self.S1 + 2 * self.v_scale) / (N + 2 * self.v_shape + 2)
J = self.network == 1
N1 = J.sum()
if update_spatial:
#B = len(self.D.block)
self.std = np.sqrt(
(self.s4 + 2*self.std_scale) / np.random.chisquare(df=self.D.U.size + 2*self.std_shape))
J = self.network == 1
if J.sum() > 0:
post_rate = rate[J] + size[J]
self.m_mean[J] = self.s3[J] / post_rate
+ np.random.randn(J.sum()) * np.sqrt(self.m_var[J] / post_rate)
tot_var = v + self.vardata
cond_mean = (v * self.data + self.vardata * m) / tot_var
cond_var = T * v * self.vardata / tot_var
self.X = cond_mean + np.random.randn(n, p) * np.sqrt(cond_var)
def update_mean_effect(self, T=1.0):
"""
#cond_mean = (X_sum[L] * m_var + self.v * self.m_mean[j]) / tot_var
#cond_std = np.sqrt(self.v * m_var / tot_var)
cond_mean = (X_sum[L] * m_var + v * self.m_mean[j]) / tot_var
cond_std = np.sqrt(v * m_var / tot_var)
self.m[L] = cond_mean + np.random.randn(len(L)) * cond_std
def update_labels(self):
N, r = self.labels_prior.shape
I = self.labels_prior_mask
m_mean = self.m_mean[self.label_values]
m_var = self.m_var[self.label_values]
L = (self.m[I].reshape(1, r) - m_mean)**2 / m_var
P = self.labels_prior * np.exp(-0.5 * L) / np.sqrt(m_var)
src/n/i/NiPy-OLD-HEAD/nipy/algorithms/statistics/tests/test_onesample.py NiPy-OLD(Download)
) + np.ones((40,ntrial))
for i in range(n):
Y = np.random.standard_normal((40,ntrial)) * np.sqrt((sd**2 + sigma2))
results = onesample.estimate_varatio(Y, sd)
results = onesample.estimate_varatio(Y, sd)
random[i] = results['random'].mean()
rsd[i] = results['random'].std()
# Compute the mean just to be sure it works
W = 1. / (sd**2 + results['random'])
mu = onesample.estimate_mean(Y, np.sqrt(sd**2 + results['random']))['effect']
mu = onesample.estimate_mean(Y, np.sqrt(sd**2 + results['random']))['effect']
yield assert_almost_equal, mu, (W*Y).sum(0) / W.sum(0)
rsd = np.sqrt((rsd**2).mean() / ntrial)
T = np.fabs((random.mean() - sigma2) / (rsd / np.sqrt(n)))
# should fail one in every 1/p trials at least for sigma > 0,
src/n/i/NiPy-OLD-HEAD/nipy/neurospin/group/spatial_relaxation_onesample.py NiPy-OLD(Download)
if update_spatial:
#B = len(self.D.block)
self.std = np.sqrt(
(self.S4 + 2 * self.std_scale) / (self.D.U.size + 2 * self.std_shape + 2))
self.v = (self.S1 + 2 * self.v_scale) / (N + 2 * self.v_shape + 2)
J = self.network == 1
N1 = J.sum()
if update_spatial:
#B = len(self.D.block)
self.std = np.sqrt(
(self.s4 + 2*self.std_scale) / np.random.chisquare(df=self.D.U.size + 2*self.std_shape))
J = self.network == 1
if J.sum() > 0:
post_rate = rate[J] + size[J]
self.m_mean[J] = self.s3[J] / post_rate
+ np.random.randn(J.sum()) * np.sqrt(self.m_var[J] / post_rate)
tot_var = v + self.vardata
cond_mean = (v * self.data + self.vardata * m) / tot_var
cond_var = T * v * self.vardata / tot_var
self.X = cond_mean + np.random.randn(n, p) * np.sqrt(cond_var)
def update_mean_effect(self, T=1.0):
"""
#cond_mean = (X_sum[L] * m_var + self.v * self.m_mean[j]) / tot_var
#cond_std = np.sqrt(self.v * m_var / tot_var)
cond_mean = (X_sum[L] * m_var + v * self.m_mean[j]) / tot_var
cond_std = np.sqrt(v * m_var / tot_var)
self.m[L] = cond_mean + np.random.randn(len(L)) * cond_std
def update_labels(self):
N, r = self.labels_prior.shape
I = self.labels_prior_mask
m_mean = self.m_mean[self.label_values]
m_var = self.m_var[self.label_values]
L = (self.m[I].reshape(1, r) - m_mean)**2 / m_var
P = self.labels_prior * np.exp(-0.5 * L) / np.sqrt(m_var)
src/m/a/matplotlib-HEAD/matplotlib/examples/pylab_examples/quadmesh_demo.py matplotlib(Download)
Qx = np.cos(Y) - np.cos(X) Qz = np.sin(Y) + np.sin(X) Qx = (Qx + 1.1) Z = np.sqrt(X**2 + Y**2)/5; Z = (Z - Z.min()) / (Z.max() - Z.min()) # The color array can include masked values:
src/p/y/pyfusion-HEAD/examples/Boyds/wid_specgram.py pyfusion(Download)
""" from matplotlib.widgets import RadioButtons, Button import pylab as pl from numpy import sin, pi, ones, hanning, hamming, bartlett, kaiser, arange, blackman, cos, sqrt, log10, fft import pyfusion
def local_wider(vec):
""" Flat top in middle, cos at edges - meant to be narrower in f
but not as good in the wings
"""
N=len(vec)
k=arange(N)
w = sqrt(sqrt(1 - cos(2*pi*k/(N-1))))
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next