Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
February 5th, 2013, 12:42 AM
 baloneybrains
Registered User

Join Date: Feb 2013
Posts: 1
Time spent in forums: 6 m 40 sec
Reputation 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
February 5th, 2013, 11:49 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,140
Time spent in forums: 1 Month 3 Weeks 2 Days 7 h 17 m 40 sec
Reputation Power: 455
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.
__________________
[code]Code tags[/code] are essential for python code!

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Some Python HW help