### Thread: Some Python HW help

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Feb 2013
Posts
1
Rep Power
0

#### Some Python HW help

here is the section of the assignment and what I have so far. I dont have a very good grasp of reshaping arrays so I feel like I'm just plug and chugging at this point

4. Compute the average height that Falls Lake is relative to its target
# for each month over the 23 years from 1985-2007, and display as bar
# chart with a bar for each month. Plot the line for 2007 in red on
# top of this bar chart.

# start a new figure for the this part

pylab.figure(4)

# put code here to compute FallsByMonth

numRows = depth.shape[1] / 23
qData = np.reshape( depth[:,0]-251.5, (numRows, -1), order = 'F')
FallsByMonth = np.mean( qData, axis = 0 )
FallsByMonth = np.reshape( FallsbyMonth, (-1,12), order='F')

# then you can create a bar chart of it like this:
# pylab.bar(np.arange(1,13), FallsByMonth, align='center')

pylab.bar(np.arange(1,13) , FallsByMonth, align = 'center')

# then plot a line in red on top of that with a call to plot like this:
# pylab.plot(np.range(1,13), something_goes_here, 'r')

pylab.plot(np.range(1,13), FallsByMonth[13], 'r')
pylab.title('Average Falls lake depth 85-07, and line for 2007')
pylab.ylabel('Height above target(ft)')
pylab.xlabel('Month')
pylab.savefig('Fig3.png')
pylab.show(4)
2. I'll admit to having found
average height that Falls Lake but it would be better if you showed a complete program (with imports) and the data.

You asked about reshape, and reshape requires that the product of the axes lengths matches the the length of the flattened data. So it's important to know exactly what you've got.