本文整理汇总了Python中scipy.io.matlab.mio.loadmat函数的典型用法代码示例。如果您正苦于以下问题:Python loadmat函数的具体用法?Python loadmat怎么用?Python loadmat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了loadmat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_str_round
def test_str_round():
# from report by Angus McMorland on mailing list 3 May 2010
stream = BytesIO()
in_arr = np.array(['Hello', 'Foob'])
out_arr = np.array(['Hello', 'Foob '])
savemat(stream, dict(a=in_arr))
res = loadmat(stream)
# resulted in ['HloolFoa', 'elWrdobr']
assert_array_equal(res['a'], out_arr)
stream.truncate(0)
stream.seek(0)
# Make Fortran ordered version of string
in_str = in_arr.tostring(order='F')
in_from_str = np.ndarray(shape=a.shape,
dtype=in_arr.dtype,
order='F',
buffer=in_str)
savemat(stream, dict(a=in_from_str))
assert_array_equal(res['a'], out_arr)
# unicode save did lead to buffer too small error
stream.truncate(0)
stream.seek(0)
in_arr_u = in_arr.astype('U')
out_arr_u = out_arr.astype('U')
savemat(stream, {'a': in_arr_u})
res = loadmat(stream)
assert_array_equal(res['a'], out_arr_u)
开发者ID:ChadFulton,项目名称:scipy,代码行数:27,代码来源:test_mio.py
示例2: plot_gaps
def plot_gaps(name, axis):
"""Takes the file name and coordinate axis and plots the marker gaps"""
runDict = {}
# load the matlab data file into a dictionary
mio.loadmat(name, mdict=runDict)
# name the rider depending on the filename
if name[0] == '1':
rider = 'Jodi'
runDict['gearing']=runDict['gear']
elif name[0] == '2':
rider = 'Victor'
else:
rider = 'Jason'
speed = np.average(runDict['V'])
# only look at one marker dimension (i.e. 'xori')
v = np.isnan(runDict[axis])
# set the figure size
fig = figure(1, figsize=(15., 9.))
matshow(v.T, fignum=1, aspect='auto', cmap=cm.gray)
yticks(range(np.shape(v)[1]), labels)
xlabel('Sample Number')
ylabel('Marker gaps in the {axis} coordinate'.format(axis=axis[0]))
title(('File: {name}, {rider} riding the {bike} at {speed} km/h while' +
' {condition} in gear {gear}').format(name=name, rider=rider, bike=runDict['bike'][0],
speed=str(speed), condition=runDict['condition'][0],
gear=runDict['gearing'][0][0]))
fig.savefig('gapImages/'+name[0:-4]+axis[0]+'.png')
show()
开发者ID:gilbertgede,项目名称:MotionCapture,代码行数:28,代码来源:plotgaps.py
示例3: create_Q_matrix
def create_Q_matrix(kappa, folder, ridge=1e-6):
GiCG = loadmat(folder + "GiCG.mat")["GiCG"]
G = loadmat(folder + "G.mat")["G"]
C0 = loadmat(folder + "C0.mat")["C0"]
Q = GiCG + 2 * (kappa ** 2) * G + (kappa ** 4) * C0
return Q + eye(Q.shape[0], Q.shape[1]) * ridge
开发者ID:lellam,项目名称:mcmc_big_g,代码行数:7,代码来源:ozone.py
示例4: test_compression
def test_compression():
arr = np.zeros(100).reshape((5,20))
arr[2,10] = 1
stream = BytesIO()
savemat(stream, {'arr':arr})
raw_len = len(stream.getvalue())
vals = loadmat(stream)
yield assert_array_equal, vals['arr'], arr
stream = BytesIO()
savemat(stream, {'arr':arr}, do_compression=True)
compressed_len = len(stream.getvalue())
vals = loadmat(stream)
yield assert_array_equal, vals['arr'], arr
yield assert_, raw_len > compressed_len
# Concatenate, test later
arr2 = arr.copy()
arr2[0,0] = 1
stream = BytesIO()
savemat(stream, {'arr':arr, 'arr2':arr2}, do_compression=False)
vals = loadmat(stream)
yield assert_array_equal, vals['arr2'], arr2
stream = BytesIO()
savemat(stream, {'arr':arr, 'arr2':arr2}, do_compression=True)
vals = loadmat(stream)
yield assert_array_equal, vals['arr2'], arr2
开发者ID:ChadFulton,项目名称:scipy,代码行数:25,代码来源:test_mio.py
示例5: test_1d_shape
def test_1d_shape():
# Current 5 behavior is 1D -> column vector
arr = np.arange(5)
stream = StringIO()
savemat(stream, {'oned':arr}, format='5')
vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (5,1)
# Current 4 behavior is 1D -> row vector
arr = np.arange(5)
stream = StringIO()
savemat(stream, {'oned':arr}, format='4')
vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (1, 5)
for format in ('4', '5'):
# can be explicitly 'column' for oned_as
stream = StringIO()
savemat(stream, {'oned':arr},
format=format,
oned_as='column')
vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (5,1)
# but different from 'row'
stream = StringIO()
savemat(stream, {'oned':arr},
format=format,
oned_as='row')
vals = loadmat(stream)
yield assert_equal, vals['oned'].shape, (1,5)
开发者ID:stefanv,项目名称:scipy3,代码行数:28,代码来源:test_mio.py
示例6: test_1d_shape
def test_1d_shape():
# Current 5 behavior is 1D -> column vector
arr = np.arange(5)
stream = BytesIO()
warn_ctx = WarningManager()
warn_ctx.__enter__()
try:
# silence warnings for tests
warnings.simplefilter('ignore')
savemat(stream, {'oned':arr}, format='5')
vals = loadmat(stream)
assert_equal(vals['oned'].shape, (5,1))
# Current 4 behavior is 1D -> row vector
stream = BytesIO()
savemat(stream, {'oned':arr}, format='4')
vals = loadmat(stream)
assert_equal(vals['oned'].shape, (1, 5))
for format in ('4', '5'):
# can be explicitly 'column' for oned_as
stream = BytesIO()
savemat(stream, {'oned':arr},
format=format,
oned_as='column')
vals = loadmat(stream)
assert_equal(vals['oned'].shape, (5,1))
# but different from 'row'
stream = BytesIO()
savemat(stream, {'oned':arr},
format=format,
oned_as='row')
vals = loadmat(stream)
assert_equal(vals['oned'].shape, (1,5))
finally:
warn_ctx.__exit__()
开发者ID:ahojnnes,项目名称:scipy,代码行数:34,代码来源:test_mio.py
示例7: test_recarray
def test_recarray():
# check roundtrip of structured array
dt = [('f1', 'f8'),
('f2', 'S10')]
arr = np.zeros((2,), dtype=dt)
arr[0]['f1'] = 0.5
arr[0]['f2'] = 'python'
arr[1]['f1'] = 99
arr[1]['f2'] = 'not perl'
stream = BytesIO()
savemat(stream, {'arr': arr})
d = loadmat(stream, struct_as_record=False)
a20 = d['arr'][0,0]
yield assert_equal, a20.f1, 0.5
yield assert_equal, a20.f2, 'python'
d = loadmat(stream, struct_as_record=True)
a20 = d['arr'][0,0]
yield assert_equal, a20['f1'], 0.5
yield assert_equal, a20['f2'], 'python'
# structs always come back as object types
yield assert_equal, a20.dtype, np.dtype([('f1', 'O'),
('f2', 'O')])
a21 = d['arr'].flat[1]
yield assert_equal, a21['f1'], 99
yield assert_equal, a21['f2'], 'not perl'
开发者ID:ChadFulton,项目名称:scipy,代码行数:25,代码来源:test_mio.py
示例8: test_multiple_open
def test_multiple_open():
# Ticket #1039, on Windows: check that files are not left open
tmpdir = mkdtemp()
try:
x = dict(x=np.zeros((2, 2)))
fname = pjoin(tmpdir, "a.mat")
# Check that file is not left open
savemat(fname, x)
os.unlink(fname)
savemat(fname, x)
loadmat(fname)
os.unlink(fname)
# Check that stream is left open
f = open(fname, 'wb')
savemat(f, x)
f.seek(0)
f.close()
f = open(fname, 'rb')
loadmat(f)
f.seek(0)
f.close()
finally:
shutil.rmtree(tmpdir)
开发者ID:ChadFulton,项目名称:scipy,代码行数:27,代码来源:test_mio.py
示例9: test_mat_struct_squeeze
def test_mat_struct_squeeze():
stream = BytesIO()
in_d = {"st": {"one": 1, "two": 2}}
savemat_future(stream, in_d)
# no error without squeeze
out_d = loadmat(stream, struct_as_record=False)
# previous error was with squeeze, with mat_struct
out_d = loadmat(stream, struct_as_record=False, squeeze_me=True)
开发者ID:jsren,项目名称:sdp-vision-env,代码行数:8,代码来源:test_mio.py
示例10: test_miutf8_for_miint8_compromise
def test_miutf8_for_miint8_compromise():
# Check reader accepts ascii as miUTF8 for array names
filename = pjoin(test_data_path, 'miutf8_array_name.mat')
res = loadmat(filename)
assert_equal(res['array_name'], [[1]])
# mat file with non-ascii utf8 name raises error
filename = pjoin(test_data_path, 'bad_miutf8_array_name.mat')
with assert_raises(ValueError):
loadmat(filename)
开发者ID:Kitchi,项目名称:scipy,代码行数:9,代码来源:test_mio.py
示例11: load_ozone_data
def load_ozone_data():
folder = OzonePosterior.get_data_folder()
y = loadmat(folder + "y.mat")["y"][:, 0]
assert(len(shape(y)) == 1)
A = loadmat(folder + "A.mat")["A"]
return y, A
开发者ID:karlnapf,项目名称:ozone-roulette,代码行数:9,代码来源:OzonePosterior.py
示例12: create_Q_matrix
def create_Q_matrix(self, kappa):
folder = OzonePosterior.get_data_folder()
GiCG = loadmat(folder + "GiCG.mat")["GiCG"]
G = loadmat(folder + "G.mat")["G"]
C0 = loadmat(folder + "C0.mat")["C0"]
Q = GiCG + 2 * (kappa ** 2) * G + (kappa ** 4) * C0
return Q + eye(Q.shape[0], Q.shape[1]) * OzonePosterior.ridge
开发者ID:karlnapf,项目名称:ozone-roulette,代码行数:9,代码来源:OzonePosterior.py
示例13: load_ozone_data
def load_ozone_data(folder):
# actual observations
y = loadmat(folder + "y.mat")["y"][:, 0]
assert(y.ndim == 1)
# triangulation of globe
A = loadmat(folder + "A.mat")["A"]
return y, A
开发者ID:lellam,项目名称:mcmc_big_g,代码行数:9,代码来源:ozone.py
示例14: test_warnings
def test_warnings():
fname = pjoin(test_data_path, 'testdouble_7.1_GLNX86.mat')
warnings.simplefilter('error')
# This should not generate a warning
mres = loadmat(fname, struct_as_record=True)
# This neither
mres = loadmat(fname, struct_as_record=False)
# This should - because of deprecated system path search
yield assert_raises, DeprecationWarning, find_mat_file, fname
warnings.resetwarnings()
开发者ID:e-johnson,项目名称:AndroidProject,代码行数:10,代码来源:test_mio.py
示例15: test_miuint32_compromise
def test_miuint32_compromise():
# Reader should accept miUINT32 for miINT32, but check signs
# mat file with miUINT32 for miINT32, but OK values
filename = pjoin(test_data_path, 'miuint32_for_miint32.mat')
res = loadmat(filename)
assert_equal(res['an_array'], np.arange(10)[None, :])
# mat file with miUINT32 for miINT32, with negative value
filename = pjoin(test_data_path, 'bad_miuint32.mat')
with assert_raises(ValueError):
loadmat(filename)
开发者ID:Kitchi,项目名称:scipy,代码行数:10,代码来源:test_mio.py
示例16: test_loadmat_varnames
def test_loadmat_varnames():
# Test that we can get just one variable from a mat file using loadmat
eg_file = pjoin(test_data_path, "testmulti_7.4_GLNX86.mat")
sys_v_names = ["__globals__", "__header__", "__version__"]
vars = loadmat(eg_file)
assert_equal(set(vars.keys()), set(["a", "theta"] + sys_v_names))
vars = loadmat(eg_file, variable_names=["a"])
assert_equal(set(vars.keys()), set(["a"] + sys_v_names))
vars = loadmat(eg_file, variable_names=["theta"])
assert_equal(set(vars.keys()), set(["theta"] + sys_v_names))
开发者ID:jsren,项目名称:sdp-vision-env,代码行数:10,代码来源:test_mio.py
示例17: test_warnings
def test_warnings():
# This test is an echo of the previous behavior, which was to raise a
# warning if the user triggered a search for mat files on the Python system
# path. We can remove the test in the next version after upcoming (0.13)
fname = pjoin(test_data_path, 'testdouble_7.1_GLNX86.mat')
with warnings.catch_warnings():
warnings.simplefilter('error')
# This should not generate a warning
mres = loadmat(fname, struct_as_record=True)
# This neither
mres = loadmat(fname, struct_as_record=False)
开发者ID:ChadFulton,项目名称:scipy,代码行数:11,代码来源:test_mio.py
示例18: test_mat_struct_squeeze
def test_mat_struct_squeeze():
stream = BytesIO()
in_d = {'st':{'one':1, 'two':2}}
savemat(stream, in_d)
# no error without squeeze
out_d = loadmat(stream, struct_as_record=False)
# previous error was with squeeze, with mat_struct
out_d = loadmat(stream,
struct_as_record=False,
squeeze_me=True,
)
开发者ID:ChadFulton,项目名称:scipy,代码行数:11,代码来源:test_mio.py
示例19: test_warnings
def test_warnings():
fname = pjoin(test_data_path, 'testdouble_7.1_GLNX86.mat')
warn_ctx = WarningManager()
warn_ctx.__enter__()
try:
warnings.simplefilter('error')
# This should not generate a warning
mres = loadmat(fname, struct_as_record=True)
# This neither
mres = loadmat(fname, struct_as_record=False)
# This should - because of deprecated system path search
assert_raises(DeprecationWarning, find_mat_file, fname)
finally:
warn_ctx.__exit__()
开发者ID:ahojnnes,项目名称:scipy,代码行数:14,代码来源:test_mio.py
示例20: test_save_object
def test_save_object():
class C(object): pass
c = C()
c.field1 = 1
c.field2 = 'a string'
stream = BytesIO()
savemat_future(stream, {'c': c})
d = loadmat(stream, struct_as_record=False)
c2 = d['c'][0,0]
assert_equal(c2.field1, 1)
assert_equal(c2.field2, 'a string')
d = loadmat(stream, struct_as_record=True)
c2 = d['c'][0,0]
assert_equal(c2['field1'], 1)
assert_equal(c2['field2'], 'a string')
开发者ID:ahojnnes,项目名称:scipy,代码行数:15,代码来源:test_mio.py
注:本文中的scipy.io.matlab.mio.loadmat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论