程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The essential difference between float32 and float64 (the influence of type on deep learning and the use of Python)

編輯:Python

First, we need to know what is bits and bytes?

  1. bits: Named digit
  2. bytes: For bytes
  3. A simple number is MB and G The relationship between ! that 8bits=1bytes, The following is the mutual transformation of various units !

  that float32 and float64 What's the difference ?

  1. The difference between digits
  2. One takes up a share of memory 32 and 64 individual bits, That is to say 4bytes or 8bytes
  3. The higher the number of digits, the higher the precision of floating-point numbers

It will affect the computational efficiency of deep learning ?

float64 Occupied memory is float32 Twice as many , yes float16 Of 4 times ; For example, for CIFAR10 Data sets , If the float64 To express , need 60000*32*32*3*8/1024**3=1.4G, Just putting data sets into memory requires 1.4G; If the float32, It only needs 0.7G, If the float16, It only needs 0.35G about ; How much memory does it take , It will have a serious impact on the operation efficiency of the system ;( Therefore, the data set files adopt uint8 To store data , Keep files to a minimum )

Pandas Table of memory occupied by each data type

Python Use numpy Set the data type to float32

import numpy as np
data = np.array([1,2,3,4,5,6,7,8,9],dtype='float32')

pandas analysis float32 and 64 Memory footprint

pandas The reason why the data processing speed is fast is that it loads the data into the memory for processing , Use pandas Load data to test different data types , Memory occupied by the same data ~

import pandas as pd
data = pd.DataFrame([1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9], dtype="float64")
data1 = pd.DataFrame([1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9], dtype="float32")
print(data.info(memory_usage=True))
print(data1.info(memory_usage=True))

  The results are as follows , We just need to check the memory size ,float64 Data occupancy 192bytes,float32 Data occupancy 160bytes

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 8 entries, 0 to 7
Data columns (total 1 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   0       8 non-null      float64
dtypes: float64(1)
memory usage: 192.0 bytes       -----------------> Memory usage
None
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 8 entries, 0 to 7
Data columns (total 1 columns):
 #   Column  Non-Null Count  Dtype  
---  ------  --------------  -----  
 0   0       8 non-null      float32
dtypes: float32(1)
memory usage: 160.0 bytes        -----------------> Memory usage
None


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved