本文整理汇总了Python中scipy.io.savemat函数的典型用法代码示例。如果您正苦于以下问题:Python savemat函数的具体用法?Python savemat怎么用?Python savemat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了savemat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: store
def store(self, filename=None, label=None, desc=None, date=None):
"""Store object to mat-file. TODO: determine format specification
"""
date = date if date else datetime.now()
date = date.replace(microsecond=0).isoformat()
filename = filename if filename else date + '.mat'
matfile = {
'model': str(type(self)),
'date': date,
'dim': len(self.init_sol.shape),
'dimlesses': self.coeffs,
'init_solution': self.init_sol,
'num_iters': self.num_iters,
'num_nodes': self.num_nodes,
'order': self.order,
'originals': self.originals,
'pumping': self.getPumping(),
'spatial_step': self.dx,
'time_step': self.dt,
}
if desc:
matfile['desc'] = desc
if label:
matfile['label'] = label
savemat(filename, matfile)
开发者ID:daskol,项目名称:nls,代码行数:28,代码来源:model.py
示例2: vti2mat
def vti2mat(fileIn, fileOut):
"""Convert voxel-array from VTI to MAT (MATLAB(R)) format.
Parameters
----------
fileIn : str
Path for input VTI file.
fileOut : str
Path for output MAT file.
"""
import numpy as np
import vtk
import scipy.io as sio
from vtk.util import numpy_support as nps
from math_utils import lcmm
reader = vtk.vtkXMLImageDataReader()
reader.SetFileName(fileIn)
reader.Update()
vtkImageData = reader.GetOutput()
dim = vtkImageData.GetDimensions()
flatV = nps.vtk_to_numpy(vtkImageData.GetPointData().GetScalars())
V = flatV.reshape(dim[::-1])
spacing = np.array(vtkImageData.GetSpacing())[::-1]
estimatedFactors = lcmm(*spacing) / spacing
estimatedVoxelSize = 1. / estimatedFactors
sio.savemat(fileOut, {'volume':V, 'spacing': spacing, 'estimated_voxel_size': estimatedVoxelSize})
开发者ID:AlfiyaZi,项目名称:Py3DFreeHandUS,代码行数:30,代码来源:converters.py
示例3: diagrams2cellarray
def diagrams2cellarray( dia_list, outname, chop_inf=True, mat_type=np.float ):
"""dia_list : n-length list of k x 2 diagrams
outname : name of output file. '.mat' will be automatically appended.
Optional:
--------
chop_inf : Remove the row corresponding to the infinite generator.
mat_type : some matlab programs expect a certain data type for
diagrams (eg. Error using '+' will be thrown). defaults to
double. Standard options should diverge far from np.int, np.float,
np.int64, etc.
Recipe from http://docs.scipy.org/doc/scipy/reference/tutorial/io.html#matlab-cell-arrays
"""
n = len( dia_list )
# object array to hold different length diagrams. Exclude the last
# (inf) generator if chop_inf==True.
C = np.zeros( (n,), dtype=np.object )
for i,d in enumerate( dia_list ):
# exclude last row
if chop_inf:
d = d[:-1]
if d.dtype != mat_type:
d = d.astype( mat_type )
C[i] = d
sio.savemat( outname+'.mat', { 'diagrams': C } )
开发者ID:caja-matematica,项目名称:pyTopTools,代码行数:31,代码来源:persistence_tools.py
示例4: RR_cv_estimate_alpha
def RR_cv_estimate_alpha(sspacing, tspacing, alphas):
"""
Estimate the optimal regularization parameter using grid search from a list
and via k-fold cross validation
Parameters
----------
sspacing : 2D subsampling ratio in space (in one direction)
tspacing : 1D subsampling ratio in time
alphas : list of regularization parameters to do grid search
"""
#Load all training data
(Xl_tr, mea_l, sig_l, Xh_tr,mea_h,sig_h) = data_preprocess(sspacing, tspacing)
# RidgeCV
from sklearn.linear_model import RidgeCV
ridge = RidgeCV(alphas = alphas, cv = 10, fit_intercept=False, normalize=False)
ridge.fit(Xl_tr, Xh_tr)
RR_alpha_opt = ridge.alpha_
print('\n Optimal lambda:', RR_alpha_opt)
# save to .mat file
import scipy.io as io
filename = "".join(['/data/PhDworks/isotropic/regerssion/RR_cv_alpha_sspacing',
str(sspacing),'_tspacing',str(tspacing),'.mat'])
io.savemat(filename, dict(alphas=alphas, RR_alpha_opt=RR_alpha_opt))
# return
return RR_alpha_opt
开发者ID:linhvannguyen,项目名称:PhDworks,代码行数:34,代码来源:regressionUtils.py
示例5: run
def run(self, y, x, initial_value, num_its, altered):
"""Run the model with the arguments: y_length, x_length, initial_value, number_of_iterations, altered"""
self.initialise_grid(y, x, initial_value)
self.write_file()
self.initialise_shadow_map()
self.num_iterations = num_its
# Standard parameter values
self.jump_length = 1
self.pd_s = 0.6
self.pd_ns = 0.4
self.altered = altered
if self.altered == True:
# Create the depth grid
self.depth = np.load("Gradual_Stepped_Full.npy")
self.avcount = np.zeros(num_its + 1)
# Run the model
self.main_loop()
print self.avcount
io.savemat("Counts.mat", { "count":self.avcount})
np.save("Counts.npy", self.avcount)
开发者ID:robintw,项目名称:WernerModel,代码行数:29,代码来源:werner.py
示例6: update_extra_mat
def update_extra_mat(matfile,to_remove):
""" updates the time_frames, confounds and mask_suppressed arrays to
reflect the removed volumes. However, does not change other items in
_extra.mat file
"""
mat = loadmat(matfile)
# update time_frames
ntf = np.delete(mat['time_frames'][0],to_remove)
mat.update({'time_frames': ntf})
# update confounds
ncon = np.delete(mat['confounds'],to_remove,axis = 0)
mat.update({'confounds': ncon})
# update mask_suppressed
ms = mat['mask_suppressed']
for supp in to_remove:
ms[supp][0] = 1
mat.update({'mask_suppressed': ms})
# save updated mat file
jnk, flnme = os.path.split(matfile)
savemat(os.path.join(output_dir,flnme),mat)
开发者ID:illdopejake,项目名称:ASL_TrT_project,代码行数:25,代码来源:harmonize_tag_control_frames.py
示例7: save_x
def save_x(tmpdir,x,i):
# handle both vector and matrix inputs
if x.ndim == 1:
sio.savemat(tmpdir+"/x_"+`i`+".mat", {'x': x})
else:
sio.savemat(tmpdir+"/x_"+`i`+".mat", {'x': x[:,i]})
return
开发者ID:sbordt,项目名称:markovmixing,代码行数:7,代码来源:iterate_distributions.py
示例8: write_file
def write_file(self, ofile):
'''
Writes the file
'''
# Creates the Matlab dictionary
mat_dict = {'longitude': self.longitude,
'latitude': self.latitude,
'imls': self.imls,
'imt': self.meta_info['imt'],
'period': None,
'damping': None,
'curves': self.curves,
'statistics': self.meta_info['statistics'],
'investigation_time': self.investigation_time}
if self.meta_info['imt'] == 'SA':
mat_dict['period'] = self.meta_info['period']
mat_dict['damping'] = self.meta_info['damping']
elif self.meta_info['imt'] == 'PGA':
mat_dict['period'] = 0.
mat_dict['damping'] = np.nan
else:
pass
# Save to binary
savemat(ofile, mat_dict, oned_as='row')
开发者ID:g-weatherill,项目名称:nrml_converters,代码行数:25,代码来源:hazard_curve_converter.py
示例9: createDictionary
def createDictionary(self):
fileName = QtGui.QFileDialog.getSaveFileName(self , 'Save dictionary to a file' , expanduser('~')+'/dictionary' , 'Matlab file (*.mat);;Python pickle (*.p);;Comma sep. values (*.csv);;Excel file (*.xlsx)')
if len(fileName) == 0:
return
self.displayInformation('Saving dictionary...' , flag='new')
fileName = str(fileName)
self.setDictionaryConfig()
self.setAlgorithmConfig()
config = generateFinalConfig(self.dictionaryConfig , self.dataMatrixes[self.filePath][1] , self.dataMatrixes[self.filePath][2])
time = np.arange(0,self.dataMatrixes[self.filePath][1]['numberOfSamples'])
dictionary = generateDictionary(time , config)
if fileName[-4:] == '.mat':
dic = {col_name : dictionary[col_name].values for col_name in dictionary.columns.values}
savemat(fileName , dic)
elif fileName[-2:] == '.p':
dictionary.to_pickle(fileName)
elif fileName[-4:] == '.csv':
dictionary.to_csv(fileName)
elif fileName[-5:] == '.xlsx':
dictionary.to_excel(fileName, sheet_name='dictionary')
self.displayInformation('Dictionary saved.' , flag='new')
开发者ID:tspus,项目名称:python-matchingPursuit,代码行数:27,代码来源:settingsFunctions.py
示例10: __init__
def __init__(self, userParameters):
num = 7+8
VV = np.linspace(-0.6, 0.6, num)
RR = []
for V in VV:
print("Start V = ", V)
tic = time.clock()
lL = tb.Lead(1.2, 2.0, -0.4, -0.4, 300, 0, 0)
T1 = "-0.4, 0.0; 0.0, -0.4"
B1 = tb.Insulator(5.4, 5.4, -0.4, -0.4, 5, 0, 0, V)
T2 = "-0.4, 0.0; 0.0, -0.4"
lR = tb.Lead(1.2, 2.0, -0.4, -0.4, 300, pi/2, V)
wire = tb.Chain(lL, T1, B1, T2, lR)
RR.append(self.__func3__(wire, V))
print("Result = ", RR[-1])
toc = time.clock()
print("Δt = ", toc-tic, "sec\n")
sio.savemat("result.mat", {"VV": VV, "RR": RR})
print("All calculation finish")
开发者ID:lise1020,项目名称:TBMTJ,代码行数:28,代码来源:TBApp.py
示例11: write
def write(array, file, format, varname=None):
if format == 'matlab':
savemat(file+".mat", mdict={varname: array}, oned_as='column', do_compression='true')
if format == 'npy':
save(file, array)
if format == 'text':
savetxt(file+".txt", array, fmt="%.6f")
开发者ID:industrial-sloth,项目名称:thunder,代码行数:7,代码来源:export.py
示例12: saveFVs
def saveFVs(QuadDir,NumberofFrame,gmm,nbc,halfWindows):
savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfWindows[-1]))
# if not os.path.isfile(savefilename):
XX = []
print "Saving Framwise FVS for ", QuadDir;
for numFrame in range(1,NumberofFrame+1):
filename = '{}desc{}.mat'.format(QuadDir,str(numFrame).zfill(5))
Quads = sio.loadmat(filename)['QuadDescriptors']
XX.append(Quads)
num = np.shape(XX)[0]
# fvs = np.zeros((NumberofFrame,nbc*13))
Allfvs = [np.zeros((NumberofFrame,nbc*13)) for k in range(len(halfWindows)) ]
# del fvs
print np.shape(Allfvs),' one ',np.shape(Allfvs[0])
for numFrame in xrange(1,NumberofFrame+1):
wincount = -1
for halfwin in halfWindows:
wincount+=1
XXtemp = []
for fnum in np.arange(max(0,numFrame-halfwin-1),min(numFrame+halfwin,NumberofFrame),1):
Quads = XX[fnum]
if np.shape(Quads)[0]>1:
XXtemp.extend(Quads)
num = np.shape(XXtemp)[0]
if num>0:
Allfvs[wincount][numFrame-1,:] = mytools.fisher_vector(XXtemp, gmm)
wincount = -1
for halfwin in halfWindows:
wincount+=1
savefilename = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfwin))
fvs = Allfvs[wincount]
sio.savemat(savefilename,mdict = {'fvs':fvs})
开发者ID:gurkirt,项目名称:actNet-inAct,代码行数:33,代码来源:TaskII_SaveFVs4Testdata.py
示例13: debug_ana_speed
def debug_ana_speed(nnode=1000):
# get the speed of the series solution for the calculation of the Stokeslets.
node = np.random.sample(nnode * 3).reshape((-1, 3))
b = 0.5
from time import time
cth_list = np.arange(10, 1000, 10)
dt = np.zeros_like(cth_list, dtype=np.float)
for i0, cth in enumerate(cth_list):
greenFun = detail(threshold=cth, b=b)
t0 = time()
greenFun.solve_prepare()
greenFun.solve_uxyz(node)
t1 = time()
dt[i0] = t1 - t0
PETSc.Sys.Print('cth=%d: solve stokeslets analytically use: %fs' % (cth, dt[i0]))
comm = PETSc.COMM_WORLD.tompi4py()
rank = comm.Get_rank()
if rank == 0:
savemat('debug_ana_speed.mat',
{'cth': cth_list,
'dt_ana': dt,
'node': node, },
oned_as='column')
return True
开发者ID:pcmagic,项目名称:stokes_flow,代码行数:27,代码来源:force_pipe.py
示例14: do_export_mat
def do_export_mat(fileHandle, b, f1_list, f2_list, f3_list, residualNorm, err, dp, ep, lp, rp, th, with_cover,
stokesletsInPipe_pipeFactor, vp_nodes, fp_nodes):
comm = PETSc.COMM_WORLD.tompi4py()
rank = comm.Get_rank()
fileHandle = check_file_extension(fileHandle, extension='_force_pipe.mat')
if rank == 0:
savemat(fileHandle,
{'b': b,
'f1_list': f1_list,
'f2_list': f2_list,
'f3_list': f3_list,
'residualNorm': residualNorm,
'err': err,
'dp': dp,
'ep': ep,
'lp': lp,
'rp': rp,
'th': th,
'with_cover': with_cover,
'stokesletsInPipe_pipeFactor': stokesletsInPipe_pipeFactor,
'vp_nodes': vp_nodes,
'fp_nodes': fp_nodes},
oned_as='column')
PETSc.Sys().Print('export mat file to %s ' % fileHandle)
pass
开发者ID:pcmagic,项目名称:stokes_flow,代码行数:25,代码来源:force_pipe.py
示例15: main
def main(argv):
leveldb_name = sys.argv[1]
print "%s" % sys.argv[1]
print "%s" % sys.argv[2]
print "%s" % sys.argv[3]
print "%s" % sys.argv[4]
# window_num = 1000;
# window_num = 12736;
window_num = int(sys.argv[2]);
# window_num = 2845;
start = time.time()
if 'db' not in locals().keys():
db = leveldb.LevelDB(leveldb_name)
datum = feat_helper_pb2.Datum()
ft = np.zeros((window_num, int(sys.argv[3])))
for im_idx in range(window_num):
datum.ParseFromString(db.Get(str(im_idx)))
ft[im_idx, :] = datum.float_data
print 'time 1: %f' %(time.time() - start)
sio.savemat(sys.argv[4], {'feats':ft},oned_as='row')
print 'time 2: %f' %(time.time() - start)
print 'done!'
开发者ID:SophieZhou,项目名称:caffe-multilabel,代码行数:26,代码来源:leveldb2mat.py
示例16: main
def main():
train_data_dir = sys.argv[1]
train_theta_dir = sys.argv[2]
DATA_DIR = '/media/beomjoon/New Volume/partial_path_suggestion/' + train_data_dir + '/'
THETA_DIR = '/media/beomjoon/New Volume/partial_path_suggestion/' + train_theta_dir + '/thetas/'
REWARD_DIR = DATA_DIR + 'speed_reward_mat_using_'+train_theta_dir +"/"
if not os.path.isdir(REWARD_DIR):
os.mkdir(REWARD_DIR)
theta_values=[]
theta_augmented_with_grasp = []
thetas,pregrasp_configs,goal_configs = get_all_thetas(THETA_DIR)
if len(sys.argv) < 3:
print "Please input training file and theta directories"
return -1
env_file_list = os.listdir(DATA_DIR+'/env_files/')
reward_matrix = []
for env_idx in range(len(env_file_list)):
train_env_f_name = get_file_name_with_given_idx(env_file_list,env_idx)
# load the environment file
print train_env_f_name
env = Environment()
env.Load(DATA_DIR+'env_files/'+train_env_f_name)
# simple_prob=separate(env,0)
floor = env.GetKinBody("floorwalls")
floor.Enable(False)
#env.SetViewer('qtcoin')
#restore_env(env,train_env_f_name)
pregrasp_config = pregrasp_configs[env_idx]
goal_config = goal_configs[env_idx]
robot = env.GetRobots()[0]
manipulator = robot.SetActiveManipulator('leftarm_torso')
robot.SetActiveDOFs(manipulator.GetArmIndices())
robot.SetActiveDOFValues(pregrasp_config)
# traj,planning_time,prep_time,plan_status = getMotionPlan(robot,goal_config,env)
env_theta_vals = []
s_time = time.time()
for theta in thetas:
print "speed!!! DATA_DIR = " + DATA_DIR
print "THETA_DIR = " + THETA_DIR
print "REWARD_DIR = " + REWARD_DIR
reward = via_sg_eval_theta(theta,pregrasp_config,goal_config,robot,env)
env_theta_vals.append(reward)
print time.time()-s_time
reward_matrix.append(env_theta_vals)
sio.savemat(REWARD_DIR+ 'reward_matrix'+str(env_idx)+\
'.mat',{'reward_matrix':reward_matrix} )
env.Destroy()
开发者ID:beomjoonkim,项目名称:openrave_repo,代码行数:60,代码来源:generate_reward_matrix_speed.py
示例17: Write_Mat
def Write_Mat(filename,field):
"""output the result in .mat format for matlab"""
file = open(filename, "w") # Open file for writing
io.savemat(file, field, appendmat = True, format='5', long_field_names = False)
file.close()
return None
开发者ID:zhucer2003,项目名称:PyNudg,代码行数:7,代码来源:PyNudg.py
示例18: extract_word2vec_feature
def extract_word2vec_feature(model_name, cache_file, output=None):
"""
Extract word2vec feature with cleaned news
:param model_name: word2vec model name
:param cache_file: news cache file path
:param output: path to save extracted features
:return: feature file path
"""
if not output:
output = get_word2vec_feature_file(cache_file)
logger.info('Word2vec feature will be extracted to: {}'.format(output))
word2vec_model = Word2VecModel(model_name)
num_samples, cleaned_news_cache = load_cache(cache_file,
__CACHE_KEY_NUM_IDS__,
__CACHE_KEY_CLEANED_NEWS__)
_features = np.zeros((num_samples, word2vec_model.model.vector_size))
pbar = data_util.get_progress_bar(num_samples)
pbar.start()
count = 0
for words in SentenceIterator(cleaned_news_cache):
_features[count] = word2vec_model.get_word_vector(words)
count += 1
pbar.update(count)
pbar.finish()
collection = {
'pooling': __POOLING__,
'norm': __NORM__,
__CACHE_KEY_WORD2VEC_MODEL__: model_name,
__CACHE_KEY_FEATURE__: _features
}
collection.update(load_cache(cache_file))
sio.savemat(output, collection)
logger.info('feature saved to: {}'.format(output))
return output
开发者ID:Dectinc,项目名称:city_judge,代码行数:35,代码来源:update_models.py
示例19: test
def test(self, phase):
test = {}
print '=========================================================='
print ' ==== Test map in all ===='
print '=========================================================='
if phase == 'test' and self.load(self.checkpoint_dir):
print(" [*] Load SUCCESS")
else:
print(" [!] Load failed...")
test['qBX'] = self.generate_code(self.query_X, self.bit, "image")
test['qBY'] = self.generate_code(self.query_Y, self.bit, "text")
test['rBX'] = self.generate_code(self.retrieval_X, self.bit, "image")
test['rBY'] = self.generate_code(self.retrieval_Y, self.bit, "text")
test['mapi2t'] = calc_map(test['qBX'], test['rBY'], self.query_L, self.retrieval_L)
test['mapt2i'] = calc_map(test['qBY'], test['rBX'], self.query_L, self.retrieval_L)
test['mapi2i'] = calc_map(test['qBX'], test['rBX'], self.query_L, self.retrieval_L)
test['mapt2t'] = calc_map(test['qBY'], test['rBY'], self.query_L, self.retrieval_L)
print '=================================================='
print '...test map: map(i->t): %3.3f, map(t->i): %3.3f' % (test['mapi2t'], test['mapt2i'])
print '...test map: map(t->t): %3.3f, map(i->i): %3.3f' % (test['mapt2t'], test['mapi2i'])
print '=================================================='
# Save hash code
datasetStr = DATA_DIR.split('/')[-1]
dataset_bit_net = datasetStr + str(bit) + netStr
savePath = '/'.join([os.getcwd(), 'Savecode', dataset_bit_net + '.mat'])
if os.path.exists(savePath):
os.remove(savePath)
sio.savemat(dataset_bit_net, {'Qi': test['qBX'], 'Qt': test['qBY'],
'Di': test['rBX'], 'Dt': test['rBY'],
'retrieval_L': L['retrieval'], 'query_L': L['query']})
开发者ID:StatML,项目名称:SSAH,代码行数:33,代码来源:SSAH.py
示例20: saveClfOut
def saveClfOut(QuadDir,OutDir,halfwins,Numberofframe,svmclf,nbc):
for halfwin in halfwins:
outFile = '{}Classfication_nbc_{}_halfwin{}.mat'.format(OutDir,str(nbc),str(halfwin))
# if not os.path.isfile(outFile):
FVsFile = "{}FVS/FVsnbc_{}_halfwin_{}.mat".format(QuadDir,str(nbc),str(halfwin))
fvs = sio.loadmat(FVsFile)['fvs']
vecAllfvs = np.zeros((Numberofframe,nbc*13))
isFrame_labeled = np.zeros(Numberofframe)
i = 0;
for fnum in xrange(Numberofframe):
fvsum = np.sum(fvs[fnum])
if abs(fvsum)>0:
vecAllfvs[i,:] = fvs[i,:]
isFrame_labeled[fnum] = 1
i+=1
vecAllfvs = vecAllfvs[:i,:]
vecAllfvs = mytools.power_normalize(vecAllfvs,0.2)
frame_probs = svmclf.predict_proba(vecAllfvs)
frame_label = svmclf.predict(vecAllfvs)
frame_probstemp = np.zeros((Numberofframe,20))
frame_probstemp[isFrame_labeled>0,:] = frame_probs
frame_labelstemp = np.zeros(Numberofframe)
frame_labelstemp[isFrame_labeled>0]=frame_label
print 'saving to ' , outFile
sio.savemat(outFile,mdict={'frame_probs':frame_probstemp, 'frame_label':frame_labelstemp,
'isFrame_labeled':isFrame_labeled})
开发者ID:gurkirt,项目名称:actNet-inAct,代码行数:28,代码来源:TaskIII_SaveClassifcationWindow.py
注:本文中的scipy.io.savemat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论