I am new to Python. I need to store multiple outputs in an empty array. For the single case, my codes work very well but have no idea how to modify this for multiple outputs. The working of my script is as below:
- load the data
- pick for column
- change into an array
- define an empty array
- run a for loop to randomly pick 2 elements (1000 times) from the array and then sum these two-element randomly picked elements and then store them in the pre-define empty array.
What I am looking for:
I need to modify this code for random picking of 2, 6, 12, 24, and 72 elements and then sum for each case and store in the empty array/data frame.
import pandas as pd # Reading Table
import numpy as np # Processing Array
import scipy.stats # Computing Statistic
import matplotlib.pyplot as plt # Drawing Graph
from scipy import stats
data = pd.read_csv("per-hour.txt", sep='\t',header=None) # Define the header names
a=list(data[0])
bb= np.array(a)
N = 1000
sum_data = [ ]
for i in range(N):
x=np.random.choice(bb, size=2, replace=True)
c=np.sum(x)
sum_data.append(c)
df = pd.DataFrame(sum_data)
df.to_csv('uuuhourly_event.csv')
Aucun commentaire:
Enregistrer un commentaire