简体   繁体   English

在python中默认如何在'float32'模式下工作?

[英]How to work in 'float32' mode by default in python?

I am working with 100s of big .csv file size of approx 500GB. 我正在使用100个约500GB的.csv大文件。 It is becoming difficult to handle this much of big data so I want to reduce overhead by converting float64 into float32 . 处理如此大量的大数据变得越来越困难,因此我想通过将float64转换为float32来减少开销。 I had done it explicitly with astype('float32') but it is converting back to float64 after an arithmetic operation. 我已经使用astype('float32')显式地完成了此操作,但是经过算术运算后它会转换回float64

data.dtypes -> dtype('float64')

data32 = data.astype('float32')
data32.dtypes -> dtype('float32')

#after a float operation
data_f = data32*1.01       #######-> I want to keep data type float32 after operation
data_f.dtypes -> dtype('float64')

I want to keep the default result in 32-bit mode . 我想将默认结果保留在32-bit mode I have found one similar question but it was asked almost a decade ago. 我发现了一个类似的问题,但是差不多十年前有人问过。 I am hoping to get a fix for this so that I can set 32bit operation globally. 我希望对此进行修复,以便可以全局设置32bit操作。

Use pandas to read the csv and specify the type of each columns ; 使用pandas读取csv并指定每列的类型; use pandas to write back the csv. 用熊猫写回csv。
You can also use numpy for (fast) arithmetic operations and specify the dtype float32 that is not available in pure python. 您还可以将numpy用于(快速)算术运算,并指定纯python中不可用的dtype float32。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM