I have a list of 43 objects and then each object includes 75 points. Each of those 75 points shows a specific time of the day and I want to get the standard deviation of that exact time from each of those 43 objects. I read that I should use a nested for loop but it shows a matrix of zeros. Can anyone help me?
y1 = [
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20,
a21, a22, a23, a24, a25, a26, a27, a28, a29, a30,
a31, a32, a33, a34, a35, a36, a37, a38, a39, a40,
a41, a42, a43
]
#an example of what 'a' is
a1 = np.array(df1['Level'][33:108])
a2 = np.array(df1['Mlevel'][105:180])
#get the standard deviation
SD = []
for i in range(43):
for j in range(75):
SD.append(np.std(y1[i[j]]))
#plot the standard deviation with mean
for i in range(43):
axs[0].plot(x1, mean_y1 + SD, color='lightblue')
axs[0].plot(x1, mean_y1 - SD, color='lightblue')
So basically what I want is to repeat the loop below for j = 0 to 75 but it does not work.
c0 = []
for i in range(43):
c0.append((y1[i][0]))
print(np.std(c0))
So in case anyone is interested I figured it out and the code below works:
#create a list of all the elements (c)
c = []
for j in range(75):
for i in range(43):
c.append((y1[i][j]))
#print(c)
#Get the standard deviation of every 43 points
start = 0 # First to consider
stop = 3225 # the length of the list c
interval = 43 # chunk size
SD = []
for i in range(start, stop, interval):
SD.append(np.std(c[i:(i + interval)]))
print(SD)
intthe right is:SD.append(np.std(y1[i][j]))