Python double into float32

Source: Internet
Author: User

Today, when dealing with Python data, I found that the imported Mat file type is double (the MATLAB default type is double). And the data I need to use is the float32 type. Finding the data did not find a suitable solution. Later, I tried, just to do the purpose of conversion. So write it down, and with the king, also hope to be able to criticize correct.

First we have to understand, float (single-precision specifier), double (double-precision descriptor). Single-precision 4 byte (32-bit) memory space with a value range of 3.4e-38~3.4e+38 and only seven digits valid digits. The double is a 8-byte (64-bit) memory space with a value range of 1.7e-308~1.7e+308, which provides 16-digit valid digits. And in the MATLAB single is to represent the precision. It can be implemented in Python by float32 type. (Note: In Python, you may not find a way to convert a matrix to float directly, possibly talents yourself). So my approach is:

In Matlab, the matrix type is first converted to single (A) type and saved. Opening in Python is the float32 type of data.

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.