Zanarkin Posted September 21, 2013 Share Posted September 21, 2013 (edited) Here is the question: (a) Use a for loop to create a list with ten elements in which the first is 1 and the last is 17 and the remaining elements are evenly spaced (ie so that the differences between adjacent elements are equal). Convert your result to an array using Numpy's array() function and print its contents. (b) Use Numpy's linspace() function to create an array with elements that correspond to your answer to (a). Print its contents. © Use a loop to print out the difference of the corresponding elements of your two arrays. (d) Repeat part © without using a loop.UPDATE Please read the page on looping in Python. Make sure that you don't use floating point numbers for your loop index (or you will lose marks). #Part a) #Import stuff from numpy import arange, array, linspace #Set variable for arange a = arange ( 1, 18, 16.0/9 ) #Convert to array print array ( a ) #Part b) b = array ( a ) #Set array to linspace c = linspace ( 1, 17, num=10 ) #convert to linspace print linspace ( 1, 17, num=10 ) #Part c) #Find difference of arrays with loops #Set loops j = c for i in b: sub = i-j print sub My question is, if i actually answered the question or not. It seems highly redundant all of what i did ...? Also the question says not to use floating numbers. As far as i have understood is that floats = numbers like 1.0, 2.0 etc. Well I can't use those, but in python if i don't use 16.0/9 then i can't have 10 elements that start at 1 and ends in 17. The things in # are just notes for the TA's. Otherwise we get 1 mark off. Also, part d i left it off for later because i'm tired of that question. Edited September 21, 2013 by SlayerX Quote Link to comment Share on other sites More sharing options...
Aleph Posted September 21, 2013 Share Posted September 21, 2013 (edited) how is this possible 1 3 5 7 9 11 13 15 17 Edit: I see you've discovered the issue yourself. Welcome to modern academia. You pay fuckloads of money for homework that isn't even presented in an accurate and fair way (I immediately saw the problem; there's no way anyone proofread this), are taught memorization more than the actual subject and make grades based on whether you bother to do the tedious bullshit instead of how much you know and can do. Especially if you're like me and devote that time that would be spent on homework I dunno actually learning and then score over 100% on the midterm and final but are still given a B for the course (what). Edited September 21, 2013 by Solais Quote Link to comment Share on other sites More sharing options...
Zanarkin Posted September 22, 2013 Author Share Posted September 22, 2013 I managed to make it evenly spaced within programming. All you need is to make increments of 16/9. Also, I dn't need to memorize much in this class as anything in the assignments is allowed to be looked at while in the midterms/finals Quote Link to comment Share on other sites More sharing options...
Aleph Posted September 22, 2013 Share Posted September 22, 2013 (edited) Wait what? Paste the output array. I don't feel like working out in my head how you got 10 evenly spaced integers from 1 through 17 in a 10 element array. Edit: I read the actual question. It says not to use floats for your loop index, not the actual array values. Your comments below the code block in your first post didn't make that clear at all. Edited September 22, 2013 by Solais Quote Link to comment Share on other sites More sharing options...
Zanarkin Posted September 22, 2013 Author Share Posted September 22, 2013 Er... sorry, i am not entirely sure what its asking, which is the reason for this topic. Quote Link to comment Share on other sites More sharing options...
Aleph Posted September 22, 2013 Share Posted September 22, 2013 Don't worry about it, I think you've got it. Quote Link to comment Share on other sites More sharing options...
Zanarkin Posted September 22, 2013 Author Share Posted September 22, 2013 ah, thank you :D Quote Link to comment Share on other sites More sharing options...
Mikethfc Posted September 24, 2013 Share Posted September 24, 2013 Obligatory I'll help you with your python something something bedchambers comment. Quote Link to comment Share on other sites More sharing options...
Raivix Posted September 24, 2013 Share Posted September 24, 2013 First off, your variable names suck. Second, re-read part a), and figure out why you haven't actually done what was asked of you. Quote Link to comment Share on other sites More sharing options...
Aleph Posted September 24, 2013 Share Posted September 24, 2013 Raivix is right, but the fact that you did the thing in one line that the professor wanted you to do with an unnecessary loop should be left in with a comment indicating that you're smarter than that and should be given special treatment. Kick some dirt in their face and spit on them for giving you such demeaning assignments that undermine and disrespect you. How dare they?! Quote Link to comment Share on other sites More sharing options...
Raivix Posted September 24, 2013 Share Posted September 24, 2013 While the sarcastic advice is great and all, this IS a first-year level assignment. and TAs don't give a shit if you do something that would be considered real-world correct when the assignment is asking for something else. It's also important to distinguish that different functions that give similar results can come to those results in much different ways, and especially when dealing with floating point numbers, the differences can be astonishingly large. There's a reason the prof is asking what he's asking. I personally don't know python, and I especially don't know anything about this particular library that he's using, but as far as schoolwork goes, most stuff has a reason for being done a certain way. Quote Link to comment Share on other sites More sharing options...
Aleph Posted September 24, 2013 Share Posted September 24, 2013 and they're usually pretty stupid I wasn't being sarcastic. If it's being graded by a TA then he should shove it into the professor's face on his own. He shouldn't pass up an opportunity to get on the prof's good side by showing proactivity. Quote Link to comment Share on other sites More sharing options...
Redwall Posted September 24, 2013 Share Posted September 24, 2013 (edited) how is this possible 1 3 5 7 9 11 13 15 17 lol Raivix is right, but the fact that you did the thing in one line that the professor wanted you to do with an unnecessary loop should be left in with a comment indicating that you're smarter than that and should be given special treatment. Kick some dirt in their face and spit on them for giving you such demeaning assignments that undermine and disrespect you. How dare they?! I think the loop is written incorrectly. Each difference in the corresponding elements in the two arrays should be zero since the arrays are identical. As for the floating-point thing, I think that only comes into play (for the purposes of this assignment) if you're using a while loop. Edited September 24, 2013 by Nessie Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.