I'm currently trying to build a practice linear parameter estimation python program using numpy but I've never written in python before and I'm very loose with numpy. I have a series of x,y data points that I want to loop over and build a new vector with that is a 5x1 vector containing only the y values.
Here is what I have so far that isn't working:
def data_loader():
## edit to have an i/o feature for retrieving data points later ##
data_points = np.array([[1,5.7],[2,19.2],[3,37.8],[4,67.3],[5,86.4]])
return data_points
def build_b(data_points):
b = np.empty((0,1), int)
for x in data_points:
for y in x:
b = np.append(y, axis=0)
return b
In addition I would also like to eventually have a user input for data points but that is down the road I guess.
To fetch just the Y values, use data_points[:,1]
. That says "use all rows, but only element 1 (counting from 0) of the rows".
That's a 5-element vector. Not sure why you're expecting (3,1).