Python read file--python read and save Mat file

Source: Internet
Author: User

first, let's talk . MarkDown Editor, I feel it is very convenient, because used to LaTeX , for MarkDown It 's easier to get started, but I've found that MarkDown There are several problems that have not been able to find a specific solution:

    1. the picture size problem. In LaTeX We can adjust the size of the image to fit the entire text;
    2. font, font size setting. MarkDown inside the title is quite big, but the text is too small, not very like the inside of the font.

The main findings of the above two problems lead to the edited text is very ugly.

First,Matfile

       mat data format is matlab the standard format for data storage of matlab load () function Import a mat file, using the save () mat file. For file


Load (' Data.mat ')

Save (' Data_1.mat ', ' A ')


among them, ' A ' represents the content to be saved.


Second, Read the mat file in Python

in the python can be used in Scipy.io the functions in Loadmat () Read Mat files, Functions Savemat Save the file.

1. Read the file

As in the above example:

#coding: UTF-8 "Created on May 12, 2015 @author:zhaozhiyong" "Import scipy.io as Sciodatafile = ' e://data.mat ' data = Scio.loadmat (datafile)

Note that the data Read is in the dictionary format and can be viewed through the function type (data) .

Print type (data)

results show

<type ' Dict ' >

Locate The matrix in the mat file:

Print data[' A ']

results show

[0.0.          0.0.          0.0.          0.0.          0.0.          0.0.   0.0 .......          0.0.          0.0.          0.0.          0.0.36470588 0.90196078 0.99215686 0.99607843 0.99215686 0.99215686 0.78431373 0.0627451 0.          0.0.   0.0.          0.0.          0.0.          0.0.   0 ........          0.94117647 0.22745098 0.          0.0.   0.0.          0.0.          0.0.          0.0.          0.0.          0.0.          0.0.   0.0.          0.0.          0.0.   0.0.30196078 .....          0.0.          0.0.          0.0.          0.0.          0.0.          0.0.        0.0. ]]

The format is:

<type ' Numpy.ndarray ' >

is the matrix format in NumPy.

2. Save the file

will be here the data[' A '] The matrix is re-saved to a new file Datanew.mat Medium:

datanew = ' E://datanew.mat '

Scio.savemat (datanew, {' A ':d ata[' a ']})

Note: It is saved in the form of a dictionary.

Python read file--python read and save Mat file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.