Re: [Tutor] Loops and matrices'
Reed DA (Danny) at Aera wrote: > I have a matrix which contains temperatures. The columns are time, spaced > 33 seconds apart, and the rows are depth intervals. What I'm trying to do > is create another matrix that contains the rate of change of temperature > for each depth. The array is called LS_JULY_11 and the output array should > be delta_temp I think you don't need any explicit for-loops: >>> import numpy as np >>> july = np.random.randint(0, 100, (3, 4)) >>> july array([[27, 43, 67, 12], [52, 22, 54, 26], [70, 81, 61, 49]]) >>> dt = 33.0 >>> july[1:] array([[52, 22, 54, 26], [70, 81, 61, 49]]) >>> july[:-1] array([[27, 43, 67, 12], [52, 22, 54, 26]]) >>> (july[1:]-july[:-1]) array([[ 25, -21, -13, 14], [ 18, 59, 7, 23]]) >>> (july[1:]-july[:-1])/dt array([[ 0.75757576, -0.63636364, -0.39393939, 0.42424242], [ 0.54545455, 1.78787879, 0.21212121, 0.6969697 ]]) If rows and columns are swapped in the above, just transpose the matrix before you start and again when you're done: >>> july = july.transpose() >>> july array([[27, 52, 70], [43, 22, 81], [67, 54, 61], [12, 26, 49]]) >>> ((july[1:]-july[:-1])/dt).transpose() array([[ 0.48484848, 0.72727273, -1.6667], [-0.90909091, 0.96969697, -0.84848485], [ 0., -0.60606061, -0.36363636]]) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Loops and matrices'
Alan Gauld wrote: On 30/08/11 00:26, Emile van Sebille wrote: delta_temp(i,j) = (LS_JULY_11(i,j) - LS_JULY_11(i,j-1))/TIME_STEP delta_temp access and assignment likely wants to be expressed with brackets rather than parens. And for those not speaking the US variant of English that'll be square brackets as opposed to round brackets! ;-) [ One of the sources of amusement to me when having my book reviewed was the fact that *all* the US reviewers picked up on my use of " brackets" to cover [],<>,(), {}. Apparently US usage of brackets is limited to []. Something that greatly surprised me and my English, Indian and South African colleagues! :-) ] And Australians and New Zealanders too. Any Canadians want to weigh in with an opinion? Brackets are anything that, er, brackets an expression (excluding quotation marks), where the one on the left is different from the one on the right. So: () round brackets [] square brackets {} curly brackets <> angle brackets Easier to spell than parenthesis/parentheses, but longer than brace/braces :) Strictly speaking, the chevrons (angle brackets) should be ⟨⟩ rather than less than and greater than signs, but they're hard to type at the keyboard and look too similar to round brackets in small font sizes. -- Steven ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Loops and matrices'
On 30/08/11 00:26, Emile van Sebille wrote: delta_temp(i,j) = (LS_JULY_11(i,j) - LS_JULY_11(i,j-1))/TIME_STEP delta_temp access and assignment likely wants to be expressed with brackets rather than parens. And for those not speaking the US variant of English that'll be square brackets as opposed to round brackets! ;-) [ One of the sources of amusement to me when having my book reviewed was the fact that *all* the US reviewers picked up on my use of " brackets" to cover [],<>,(), {}. Apparently US usage of brackets is limited to []. Something that greatly surprised me and my English, Indian and South African colleagues! :-) ] -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Loops and matrices'
On 8/29/2011 3:28 PM Reed DA (Danny) at Aera said... Hi all, I have a matrix which contains temperatures. The columns are time, spaced 33 seconds apart, and the rows are depth intervals. What I'm trying to do is create another matrix that contains the rate of change of temperature for each depth. The array is called LS_JULY_11 and the output array should be delta_temp What I have so far is:- import numpy #determine the existing matrix size columnsize = LS_JULY_11.columnSize() matrixsize = LS_JULY_11.size() rowsize = matrixsize/columnsize #define time step TIME_STEP = 33 #create matrix size of the same size delta_temp = numpy.zeros((rowsize,columnsize)) #cycle through all indicies in temperature matrix for i in rowsize: for j in columnsize: delta_temp(i,j) = (LS_JULY_11(i,j) - LS_JULY_11(i,j-1))/TIME_STEP j = j+1 i = i + 1 the error I get is:- File "", line 18 (33) SyntaxError: can't assign to function call delta_temp access and assignment likely wants to be expressed with brackets rather than parens. Emile ActivePython 2.6.6.15 (ActiveState Software Inc.) based on Python 2.6.6 (r266:84292, Aug 24 2010, 16:01:11) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> spam(1,2)=6 File "", line 1 SyntaxError: can't assign to function call >>> Help would be greatly appreciated Thanks Danny ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Loops and matrices'
Hi Danny, Most likely you want delta_temp(i,j) = (LS_JULY_11(i,j) - LS_JULY_11(i,j-1))/TIME_STEP to become (changed the character from '()' to '[]': delta_temp[i,j] = (LS_JULY_11(i,j) - LS_JULY_11(i,j-1))/TIME_STEP Basically it thinks "delta_temp(i,j) " is a function call and function calls cannot be assigned a value. Ramit Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology 712 Main Street | Houston, TX 77002 work phone: 713 - 216 - 5423 This email is confidential and subject to important disclaimers and conditions including on offers for the purchase or sale of securities, accuracy and completeness of information, viruses, confidentiality, legal privilege, and legal entity disclaimers, available at http://www.jpmorgan.com/pages/disclosures/email. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] Loops and matrices'
Hi all, I have a matrix which contains temperatures. The columns are time, spaced 33 seconds apart, and the rows are depth intervals. What I'm trying to do is create another matrix that contains the rate of change of temperature for each depth. The array is called LS_JULY_11 and the output array should be delta_temp What I have so far is:- import numpy #determine the existing matrix size columnsize = LS_JULY_11.columnSize() matrixsize = LS_JULY_11.size() rowsize = matrixsize/columnsize #define time step TIME_STEP = 33 #create matrix size of the same size delta_temp = numpy.zeros((rowsize,columnsize)) #cycle through all indicies in temperature matrix for i in rowsize: for j in columnsize: delta_temp(i,j) = (LS_JULY_11(i,j) - LS_JULY_11(i,j-1))/TIME_STEP j = j+1 i = i + 1 the error I get is:- File "", line 18 (33) SyntaxError: can't assign to function call Help would be greatly appreciated Thanks Danny ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor