本文整理汇总了Python中scipy.column_stack函数的典型用法代码示例。如果您正苦于以下问题:Python column_stack函数的具体用法?Python column_stack怎么用?Python column_stack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了column_stack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, which_case, LUT, RandomSamples, interp_type):
print 'SciPy Interpolating ', which_case
select = {\
"rhoe":('Density','StaticEnergy'),\
"PT":('Pressure','Temperature'),\
"Prho":('Pressure','Density'),\
"rhoT":('Density','Temperature'),\
"Ps":('Pressure','Entropy'),\
"hs":('Enthalpy','Entropy')\
}
thermo1, thermo2, = select[which_case]
x =getattr(LUT,thermo1)
y =getattr(LUT,thermo2)
samples_x = getattr(RandomSamples,thermo1)
samples_y = getattr(RandomSamples,thermo2)
setattr(self,thermo1, samples_x)
setattr(self,thermo2, samples_y)
variables = sp.array(['Temperature','Density','Enthalpy','StaticEnergy',\
'Entropy','Pressure','SoundSpeed2','dPdrho_e','dPde_rho',\
'dTdrho_e','dTde_rho','Cp','Mu','Kt']);
for var in variables[sp.where((variables!=thermo1) * (variables!=thermo2))]:
z = getattr(LUT,var)
interp_func = sp.interpolate.griddata((x,y),z,sp.column_stack((samples_x,samples_y)),\
method=interp_type)
nan_index = sp.where(sp.isnan(interp_func))
interp_func[nan_index]= sp.interpolate.griddata((x,y),z,\
sp.column_stack((samples_x[nan_index],samples_y[nan_index])),\
method='nearest')
setattr(self,var,interp_func)
return
示例2: _packData
def _packData(self, G1, indices2select, effect):
if effect == 'fixed':
if G1 is None and self.G0 is None:
data = self.X[self.data_permutation][indices2select]
elif G1 is None:
data = sp.column_stack((self.G0[self.data_permutation][indices2select],
self.X[self.data_permutation][indices2select]))
elif self.G0 is None:
data = sp.column_stack((G1[self.data_permutation][indices2select],
self.X[self.data_permutation][indices2select]))
else:
data = sp.column_stack((self.G0[self.data_permutation][indices2select],
G1[self.data_permutation][indices2select],
self.X[self.data_permutation][indices2select]))
elif effect == 'mixed':
X = self.X[self.data_permutation]
if self.G0 is not None:
G0 = self.G0[self.data_permutation]
if G1 is not None:
G1 = G1[self.data_permutation]
data = []
for i in range(len(indices2select)):
lis = [X[indices2select[i]]]
if G0 is not None:
lis.append( G0[indices2select[i]] )
if G1 is not None:
lis.append( G1[indices2select[i]] )
data.append( lis )
else:
assert False, 'Unkown effect type.'
return (data, self.Y[self.data_permutation][indices2select])
示例3: GetFermiSigns
def GetFermiSigns(filename,refstate=None,channel=None):
attr=GetAttr(filename)
filetype=''
try:
filetype=attr['type']
except KeyError:
mo=re.match('.*/?[0-9]+-(.*)\.h5',filename)
filetype=mo.groups()[0]
L=attr['L']
if refstate==None:
refstate=sc.zeros(2*L*L)
refstate[0::2]=1
if filetype=='WaveFunction':
hfile=h5py.File(filename,'r')
if 'states_up' in hfile.keys():
states=sc.column_stack([hfile['states_up'],hfile['states_do']])
else:
states=sc.column_stack([hfile['states_0'],hfile['states_1']])
hfile.close()
return sf.fermisigns(states,refstate)
else:
if channel==None:
channel=attr['channel']
L=int(attr['L'])
if 'phasex' in attr.keys():
shift=[attr['phasex']/2.0,attr['phasey']/2.0]
else:
shift=[attr['phase_shift_x']/2.0,attr['phase_shift_y']/2.0]
q=[float(attr['qx'])/L,float(attr['qy'])/L]
if channel=='trans':
return sf.transfermisigns(L,L,shift,q)
elif channel=='long':
return sf.longfermisigns(L,L,shift,q)
else:
raise KeyError('\"channel\" must be either \"trans\" or \"long\".')
示例4: writeCSVOutput
def writeCSVOutput(hdf5File=None,cout=None):
f = h5py.File(hdf5File,'r')
csv_filename = os.path.join(cout,f['phenotype_name'].value.replace(" ","_") + ".csv")
csv_header = None
csv_matrix = None
if "betas" in f.keys():
csv_header = sp.array(["CHR","Positions","P-Value","TestStatistic","Q-Value","Benjamini-Hochberg-P-Value","Benjamini-Hochberg-Yekutieli-P-Value","Beta0","SEBeta0","Beta1","SEBeta1","MAF","SNP-Hash"])
else:
csv_header = sp.array(["CHR","Positions","P-Value","TestStatistic","Q-Value","Benjamini-Hochberg-P-Value","Benjamini-Hochberg-Yekutieli-P-Value","MAF","SNP-Hash"])
tmp_matrix = None
if "betas" in f.keys():
tmp_matrix = sp.column_stack([sp.array(f["chromosomes"],dtype="S50"),
f['positions'],
f['p_values'],
f['scores'],
f['q_values'],
f['bh_p_values'],
f['bhy_p_values'],
f['betas'][:,0],
f['betas_se'][:,0],
f['betas'][:,1],
f['betas_se'][:,1],
f['maf'],
f['snp_hash']])
else:
tmp_matrix = sp.column_stack([sp.array(f["chromosomes"],dtype="S50"),
f['positions'],
f['p_values'],
f['scores'],
f['q_values'],
f['bh_p_values'],
f['bhy_p_values'],
f['maf'],
f['snp_hash']])
csv_matrix = tmp_matrix
mf = open(csv_filename,'w')
string = ""
for i in xrange(csv_header.shape[0]):
string += str(csv_header[i]) + ","
mf.write(string[:-1] + "\n")
for i in xrange(csv_matrix.shape[0]):
string = ""
for j in xrange(csv_matrix.shape[1]):
string += str(csv_matrix[i,j]) + ","
mf.write(string[:-1] + "\n")
mf.close()
f.close()
示例5: bm29write
def bm29write(self, filename= None, newdata=None, comment=True, newdatacol_head=None, columns=None):
"""function to write a bm29 file, define a series of array with the same name
of column defined in the file
input \n
filename =>string
newdata =>numpy array
comment =>boolean or new comments line
col_head =>string heders of column
columns =>list of strings with the columns to write
P.S or newdata and col_head or columns
"""
if not(filename):
try:
filename =getattr(self,"fullfilename")
except:
raise FileFormatError('no filename specified and self.fullfilenames not defined')
if os.path.exists(filename):
filename += ".1"
outFile = open(filename, 'w')
if comment is True:
if hasattr(self, "comments"):
outFile.writelines(self.comments[:-2])
elif comment is False:
pass
else: outFile.writelines(comment)
if newdata is None:
if columns:
outFile.writelines("#N "+str(len(columns))+ "\n")
col_head= "#L "+" ".join(columns)
outFile.writelines(col_head+"\n")
f=lambda x: getattr(self,x)
newdata= scipy.column_stack(map(f,columns))
else:
if self.All_Column == False:
outFile.writelines("#N 2\n")
outFile.writelines("#L E Mu\n")
newdata= scipy.column_stack((self.E, self.Mu))
elif self.All_Column == True:
try:
outFile.writelines(self.comments[-2])
outFile.write("#L "+" ".join(getattr(self, "col_head")))
outFile.write("\n")
newdata = self.data
except:
pass
scipy.savetxt(outFile, newdata, fmt= '%1.10f')
outFile.close
return
示例6: readMahalih5
def readMahalih5(filename,des_site):
""" This function will read the mahali GPS data into a GeoData data structure.
The user only has to give a filename and name of the desired site.
Input
filename - A string that holds the file name.
des_site - The site name. Should be listed in the h5 file in the
table sites.
"""
h5fn = Path(filename).expanduser()
with h5py.File(str(h5fn), "r", libver='latest') as f:
despnts = sp.where(f['data']['site']==des_site)[0]
# TODO: hard coded for now
doy = doy= f['data']['time'][despnts]
year = 2015*sp.ones_like(doy,dtype=int)
TEC = f['data']['los_tec'][despnts]
nTEC = f['data']['err_los_tec'][despnts]
vTEC = f['data']['vtec'][despnts]
az2sat = f['data']['az'][despnts]
el2sat = f['data']['az'][despnts]
piercelat = f['data']['pplat'][despnts]
piercelong = f['data']['pplon'][despnts]
satnum= f['data']['prn'][despnts]
recBias = f['data']['rec_bias'][despnts]
nrecBias = f['data']['err_rec_bias'][despnts]
# Make the integration time on the order of 15 seconds.
if (year==year[1]).all():
unixyear =(datetime(year[0],1,1,0,0,0,tzinfo=UTC) - EPOCH).total_seconds()
uttime = unixyear + sp.round_(24*3600*sp.column_stack((doy,doy+15./24./3600.))) # Making the difference in time to be a minute
else:
(y_u,y_iv) = np.unique(year,return_inverse=True)
unixyearu = sp.array([(datetime(iy,1,1,0,0,0,tzinfo=UTC) - EPOCH).total_seconds() for iy in y_u])
unixyear = unixyearu[y_iv]
uttime = unixyear + 24*3600*sp.column_stack((doy,doy+15./24./3600.))
data = {'TEC':TEC,'nTEC':nTEC,'vTEC':vTEC,'recBias':recBias,'nrecBias':nrecBias,'satnum':satnum,'az2sat':az2sat,'el2sat':el2sat}
coordnames = 'WGS84'
sensorloc = sp.nan*sp.ones(3)
dataloc = sp.column_stack((piercelat,piercelong, 350e3*sp.ones_like(piercelat)))
return (data,coordnames,dataloc,sensorloc,uttime)
示例7: kmeanspp_initialisation
def kmeanspp_initialisation( self, X ):
"""Initialise means using K-Means++"""
N, _ = X.shape
k, d = self.k, self.d
M = []
# Choose one center amongst the X at random
m = sc.random.randint( N )
M.append( X[m] )
# Choose k centers
while( len( M ) < self.k ):
# Create a probability distribution D^2 from the previous mean
D = cdist( X, M ).min( 1 )**2
assert( D.shape == (N,) )
# Normalise and sample a new point
D /= D.sum()
m = sc.random.multinomial( 1, D ).argmax()
M.append( X[m] )
M = sc.column_stack( M )
sigma = sc.sqrt(cdist( X, M.T, 'sqeuclidean').sum(0)/(N))
w = ones( k )/float(k)
return M, sigma, w
示例8: main
def main():
saved_handler = sp.seterrcall(err_handler)
saved_err = sp.seterr(all='call')
print('============ Part 1: Plotting =============================')
x, y = load_data('ex2/ex2data1.txt')
plot_data(x, y)
pl.show()
print('============ Part 2: Compute Cost and Gradient ============')
m, n = x.shape
x = sp.column_stack((sp.ones((m, 1)), x))
init_theta = sp.asmatrix(sp.zeros((n + 1, 1)))
cost, grad = cost_function(init_theta, x, y)
print('Cost at initial theta: %s' % cost)
print('Gradient at initial theta:\n %s' % grad)
print('============ Part 3: Optimizing minimize ====================')
# res = op.minimize(cost_function, init_theta, args=(x, y), jac=True, method='Newton-CG')
res = op.minimize(cost_function_without_grad, init_theta, args=(x, y), method='Powell')
# print('Cost at theta found by fmin: %s' % cost)
print('Result by minimize:\n%s' % res)
plot_decision_boundary(res.x, x, y)
pl.show()
print('============ Part 4: Optimizing fmin ====================')
res = op.fmin(cost_function_without_grad, init_theta, args=(x, y))
# print('Cost at theta found by fmin: %s' % cost)
print('Result by fmin:\n%s' % res)
plot_decision_boundary(res, x, y)
pl.show()
sp.seterrcall(saved_handler)
sp.seterr(**saved_err)
示例9: apply_flow
def apply_flow(self,flowrate):
r'''
Convert the invaded sequence into an invaded time for a given flow rate
considering the volume of invaded pores and throats.
Parameters
----------
flowrate : float
The flow rate of the injected fluid
Returns
-------
Creates a throat array called 'invasion_time' in the Algorithm
dictionary
'''
P12 = self._net['throat.conns'] # List of throats conns
a = self['throat.invasion_sequence'] # Invasion sequence
b = sp.argsort(self['throat.invasion_sequence'])
P12_inv = self['pore.invasion_sequence'][P12] # Pore invasion sequence
# Find if the connected pores were invaded with or before each throat
P1_inv = P12_inv[:,0] == a
P2_inv = P12_inv[:,1] == a
c = sp.column_stack((P1_inv,P2_inv))
d = sp.sum(c,axis=1,dtype=bool) # List of Pores invaded with each throat
# Find volume of these pores
P12_vol = sp.zeros((self.Nt,))
P12_vol[d] = self._net['pore.volume'][P12[c]]
# Add invaded throat volume to pore volume (if invaded)
T_vol = P12_vol + self._net['throat.volume']
# Cumulative sum on the sorted throats gives cumulated inject volume
e = sp.cumsum(T_vol[b]/flowrate)
t = sp.zeros((self.Nt,))
t[b] = e # Convert back to original order
self._phase['throat.invasion_time'] = t
示例10: run
def run(self):
# Parameters passed are current data array, along with time step
# between current data points
self.times = sp.arange(0,self.Tfinal,self.dt)
self.sim = odeint(self.eqns,self.init,self.times,(self.inj,self.injdt))
sp.savetxt('simulation.txt',sp.column_stack((self.times,self.sim)))
示例11: backsolve
def backsolve(self, T=None, vterm=None):
"""Solve finite system by backward recursion
Parameters
-------------
T : int, optional
Number of periods of time.
Returns
----------
X : array, shape (n, T)
Optimal controls. An optimal policy for each starting state
V : array, shape (n, T + 1)
Value function.
"""
if T is None:
if self.T is not None:
T = self.T
else:
print ("Not a finite time model")
return
if vterm is None and self.vterm is None:
vterm = sp.zeros(self.n)
else:
vterm = self.vterm
x = sp.zeros((self.n, T), dtype=int)
v = sp.column_stack((sp.zeros((self.n, T)), vterm))
pstar = sp.zeros((self.n, self.n, T))
for t in sp.arange(T - 1, -1, -1):
v[ :, t] , x[ :, t] = self.valmax(v[ : , t + 1])
pstar[..., t] = self.valpol(x[:, t])[0]
return (x, v, pstar)
示例12: recover_topics
def recover_topics( P, T, k, a0 ):
"""Recover the k components given input Pairs and Triples and
$\\alpha_0$"""
# Consider the k rank approximation of P,
P = approxk( P, k )
# Get the whitening matrix and coloring matrices
W, Wt = get_whitener( P, k )
# Whiten the third moment
Tw = lambda theta: W.T.dot( T( W.dot(theta) ) ).dot( W )
# Project Tw onto a matrix
theta = orthogonal( k ).T[0]
U, S, _ = svd( Tw( theta ) )
assert( (S > 1e-10).all() ) # Make sure it is non-singular
O = []
for i in xrange( k ):
v = U.T[i]
Zinv = (a0 + 2)/2 * (v.T.dot(Tw(v)).dot(v))
O.append( Zinv * Wt.T.dot( v ) )
O = sc.column_stack( O )
return abs( O )
示例13: makeinputh5
def makeinputh5(Iono,basedir):
"""This will make a h5 file for the IonoContainer that can be used as starting
points for the fitter. The ionocontainer taken will be average over the x and y dimensions
of space to make an average value of the parameters for each altitude.
Inputs
Iono - An instance of the Ionocontainer class that will be averaged over so it can
be used for fitter starting points.
basdir - A string that holds the directory that the file will be saved to.
"""
# Get the parameters from the original data
Param_List = Iono.Param_List
dataloc = Iono.Cart_Coords
times = Iono.Time_Vector
velocity = Iono.Velocity
zlist,idx = sp.unique(dataloc[:,2],return_inverse=True)
siz = list(Param_List.shape[1:])
vsiz = list(velocity.shape[1:])
datalocsave = sp.column_stack((sp.zeros_like(zlist),sp.zeros_like(zlist),zlist))
outdata = sp.zeros([len(zlist)]+siz)
outvel = sp.zeros([len(zlist)]+vsiz)
# Do the averaging across space
for izn,iz in enumerate(zlist):
arr = sp.argwhere(idx==izn)
outdata[izn] = sp.mean(Param_List[arr],axis=0)
outvel[izn] = sp.mean(velocity[arr],axis=0)
Ionoout = IonoContainer(datalocsave,outdata,times,Iono.Sensor_loc,ver=0,
paramnames=Iono.Param_Names, species=Iono.Species,velocity=outvel)
Ionoout.saveh5(basedir/'startdata.h5')
示例14: train
def train(self):
if self.__algo_model=="MWUrt" or self.__algo_model=="WCrt":
data = asso.MatrixData(x=self.__x,y=self.__y,covariates=self.__cov)
self.__ass.setData(data)
self.__ass.train()
else:
self.__ass.setPhenotype(self.__y)
self.__ass.setGenotype(self.__x)
if not self.__cov is None:
self.__ass.setCovariates(sp.column_stack([sp.ones(self.__y.shape),self.__cov]))
if self.__permutation==True:
if self.__x.shape[1]<1000:
self.__perms = 1000000
elif self.__x.shape[1]<10000:
self.__perms = 100000
elif self.__x.shape[1]<100000:
self.__perms = 10000
elif self.__x.shape[1]<1000000:
self.__perms = 1000
elif self.__x.shape[1]<10000000:
self.__perms = 100
else:
self.__perms = 10
print "SNPS: ", self.__x.shape[1]
print "Perms: ", self.__perms
self.__ass.permutations(self.__perms)
else:
self.__ass.test_associations()
示例15: makeinputh5
def makeinputh5(Iono,basedir):
basedir = Path(basedir).expanduser()
Param_List = Iono.Param_List
dataloc = Iono.Cart_Coords
times = Iono.Time_Vector
velocity = Iono.Velocity
zlist,idx = sp.unique(dataloc[:,2],return_inverse=True)
siz = list(Param_List.shape[1:])
vsiz = list(velocity.shape[1:])
datalocsave = sp.column_stack((sp.zeros_like(zlist),sp.zeros_like(zlist),zlist))
outdata = sp.zeros([len(zlist)]+siz)
outvel = sp.zeros([len(zlist)]+vsiz)
for izn,iz in enumerate(zlist):
arr = sp.argwhere(idx==izn)
outdata[izn]=sp.mean(Param_List[arr],axis=0)
outvel[izn]=sp.mean(velocity[arr],axis=0)
Ionoout = IonoContainer(datalocsave,outdata,times,Iono.Sensor_loc,ver=0,
paramnames=Iono.Param_Names, species=Iono.Species,velocity=outvel)
ofn = basedir/'startdata.h5'
print('writing {}'.format(ofn))
Ionoout.saveh5(str(ofn))