在Python中将大数据写入文件的最快方法

时间:2017-04-25 12:46:22

标签: python numpy file-io io fortran

我有一个大的数组〜(10 ^ 8 x 5)。我希望能够编写这个数据文件,以便在其他程序中使用。

根据enter image description here中的建议,我只使用this StackOverflow answer写入磁盘一次,而不是反复调用 import numpy as np from scipy.interpolate import interpld as interpld #Load the data data = np.loadtxt('path/to/file/file.txt') #Extract the data - let's just say it is x,y,z coordinates x = data[:,0] y = data[:,1] z = data[:,2] # Do some interpolation to increase the 'resolution' of xyz coordinates baseline = np.zeros(len(x)) for k in range(len(baseline)): baseline[k] = k N = 10000 # set resolution relative to baseline IntBaseline = np.linspace(0,baseline[-1],len(baseline)*N) gx = interpld(baseline,x) gy = interpld(baseline,y) gz = interpld(baseline,z) interpolated_x = gx(IntBaseline) interpolated_y = gy(IntBaseline) interpolated_z = gz(IntBaseline) # Now write everything to an array and save outfile = np.zeros((len(interpolated_x),3) outfile[:,0] = interpolated_x outfile[:,1] = interpolated_y outfile[:,2] = interpolated_z np.savetxt('Interpolated_Outfile.txt', outfile) 。但是,考虑到我的数据大小,这很慢并产生一个非常大的文件(~47 GB)。

我意识到我可以使用类似numpy.savetxt的东西,但我希望能够使用Fortran读取输出文件。它没有必要是人类可读的。

最佳选择/最佳做法?

由于

一些示例代码:

<html>
<head>
	<script Src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script>

	<script>
		var app=angular.module("myapp", []);
		app.controller("namesctrl", function($scope,$http){
 
        $scope.tickets = [{
                "id": 1
            },{
                "id": 2
            },{
                "id": 3
            },{
                "id": 4
            },{
                "id": 5
            }];

            $scope.random = function() {
                return 0.5 - Math.random();
            }
		});

		
	</script>


</head>
<body ng-app="myapp" ng-controller="namesctrl">
    <ul>
        <li ng-repeat="item in tickets | orderBy:random">{{i}}
               {{item.id}}
        </li>
    </ul>
</body>
</html>

0 个答案:

没有答案