我为什么使用scipy.io.savemat获取一行一列而不是两列

2024-09-30 00:34:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到两个数据,我想把它作为.mat文件 所以我用了模块scipy.io公司以及scipy.io.savemat 但当我打开文件时: enter image description here

我想得到两列950x1而不是1x950

代码如下:

import scipy.io as sio

x = Ramanshift1[64:1014]
Hem_I_Nor = pd.Normalization(y3_arpls)
sio.savemat(Hem_path+'/matdata.mat',{'ramanshift':x,'ramanspectra':Hem_I_Nor})

x来自一列 而Hem muu iu Nor来自pandas,所有这些都可以保存到.csv和两个列中


Tags: 模块文件数据ioimagehere公司scipy
1条回答
网友
1楼 · 发布于 2024-09-30 00:34:59

在numpy会话中:

In [25]: from scipy.io import savemat
In [26]: savemat('test.mat', {'x':np.ones((3,),int), 'y': np.ones((3,1),int), 'z
    ...: ': np.ones((1,3),int)})

在八度音阶中,在load之后:

^{pr2}$

它是构成(1,n)矩阵的一维数组:

^{3}$

对于2d数组,请观察order。MATLAB使用F。所以

In [31]: np.arange(12).reshape(3,4,order='F')
Out[31]: 
array([[ 0,  3,  6,  9],
       [ 1,  4,  7, 10],
       [ 2,  5,  8, 11]])

另存为

>> w
w = 
   0   3   6   9
   1   4   7  10
   2   5   8  11

由于数组/矩阵顺序的固有差异,将值从一个传递到另一个可能会令人困惑。savemat/loadmat操作不一定有帮助。在

看看文档,还有一个oned_as参数,它控制(n,)数组是保存为(n,1)还是(1,n)。在

相关问题 更多 >

    热门问题