import numpy as np import pandas as pd from array import * #make an array of 100 points x uniform distrib., btw 0-1 interval #with y as a polynomial plus a Gaussian random variable with STD = 0.5 x = np.arange(0,1,0.01) z = np.random.normal(loc=0.0, scale=.5, size=None) for i in x: y = 2+3*x+z array = np.array([y]) #print array #performs the svd calculation for array calculated above U, s, V = np.linalg.svd(array, full_matrices=True) U.shape, V.shape, s.shape print U print s print V #Bootstrap method def bootstrap_resample(X, n=None): if n == None: n = len(X) resample_i = np.floor(np.random.rand(n)*len(X)).astype(int) X_resample = X[resample_i] return X_resample X = arange(10000) X = resample = bootstrap_resample(X, n=5000) print 'original mean:', X.mean() print 'resampled mean:', X_resample.mean() #write output to a txt and csv file np.savetxt('svdmatrix.txt', array, fmt='%2.5f', delimiter=',') np.savetxt('svdmatrix.csv', array, fmt='%2.5f', delimiter=',')