将mat文件以不同的数值数据格式保存在scipy.io.savemat中 [英] Saving mat files in different numerical data formats in scipy.io.savemat

查看:609
本文介绍了将mat文件以不同的数值数据格式保存在scipy.io.savemat中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这很简单,我不敢相信我在任何地方都没有找到任何东西,但是它真的来了

I know this is very simple and I can't believe I haven't found anything on this anywhere but here it goes:

我在python中有一个大型的高维矩阵,我想以.mat格式保存(适用于Matlab). 我正在使用scipy.io.savemat方法保存此矩阵,但始终将其保存为double.我想将其保存为较低精度的内容,例如单精度或16位浮点数.

I have a large, high dimensional matrix in python that I want to save in .mat format (for matlab). I'm using the scipy.io.savemat method to save this matrix but it's always saved as double. I would like to save it as something of lower precision, like single or 16 bit float.

我在保存之前将数组转换为低精度数据类型,但始终将其保存为double.真的没有办法将Mat文件保存为较低精度的float类型吗?

I convert the array to a low-precision data type before saving but it's always saved as double. Is there really no way of saving mat files in a lower-precision float type?

.savemat似乎没有dtype参数.

.savemat does not seem to take a dtype argument.

 import scipy as sp
 sp.io.savemat('test.mat', {'test': sp.array([0.001, 1, 1.004], dtype='Float16')})

推荐答案

显然,它必须是一个或两个. scipy.io.savemat()不支持其他浮点精度,如果它不喜欢您的dtype而没有警告,它将随意默认为double.

Apparently it needs to be either single or double. scipy.io.savemat() does not support other float precisions and it'll casually default to double if it doesn't like your dtype without warning.

这篇关于将mat文件以不同的数值数据格式保存在scipy.io.savemat中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆