Week 20 Summary

This week I had major achievement in coding. With Mr. H's guide, I finally succeeded in writing a piece of code to find the relative max/min in a 2D array list:

import csv
import numpy as np
from scipy.signal import argrelextrema
import matplotlib.pyplot as plt

twoDimArray = []

def getColumn(x):
column = []
for row in twoDimArray[1:]:
column.append(float(row[x]))
return column

with open('sampletiny.csv') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for row in reader:
twoDimArray.append(row)

columns = {}
n = 0
for cell in twoDimArray[0]:
columns.update({cell:n})
n = n + 1

rows = {}
n = 0
for row in twoDimArray:
rows.update({row[0]:n})
n = n + 1
column0 = getColumn(0)
column1 = getColumn(1)

x = np.array(column0)
y = np.array(column1)

sortId = np.argsort(x)
x = x[sortId]
y = y[sortId]

#plt.plot(x-1, y)
#splt.show()
maxm = argrelextrema(y, np.greater)
minm = argrelextrema(y, np.less)
print maxm
print minm

And when I tried to run it, this is what I got without plotting:


The next step for me would be to import the huge data in csv. collected from the headset. There must have been some errors with the formatting that I could not run it with python. As long as I figure this out, I will reach my goal of software development and speed up my project progress.

Comments