hw02_student_solutions.pdf - hw02_student_solutions 1 Homework 2 Arrays and Tables Don't change this cell just run it import numpy as np from

hw02_student_solutions.pdf - hw02_student_solutions 1...

This preview shows page 1 - 3 out of 13 pages.

hw02_student_solutionsSeptember 20, 20191Homework 2: Arrays and Tables[ ]:# Don't change this cell; just run it.importnumpyasnpfromdatascienceimport*Recommended Reading: *Data Types*Sequences*TablesPlease complete this notebook by filling in the cells provided.Before you begin, execute thefollowing cell to load the provided tests. Each time you start your server, you will need to executethis cell again to load the tests.This assignment is due Thursday, September 12 at 11:59 P.M. You will receive an early submissionbonus point if you turn in your final submission by Wednesday, September 11 at 11:59 P.M. Latework will not be accepted as per thepoliciesof this course.Start early so that you can come to office hours if you’re stuck. Check the website for the officehours schedule.Throughout this homework and all future ones, please be sure to not re-assign variables throughoutthe notebook! For example, if you usemax_temperaturein your answer to one question, do notreassign it later on.Important: In this homework, theoktests will tell you whether your answer is correct, except forParts 4, 5 & 6. In future homework assignments, correctness tests will typically not be provided.Before continuing the assignment, select ”Save and Checkpoint” in the File menu and then executethe submit cell below. The result will contain a link that you can use to check that your assignmenthas been submitted successfully. If you submit more than once before the deadline, we will onlygrade your final submission. If you mistakenly submit the wrong one, you can head to okpy.organd flag the correct version. There will be another submit cell at the end of the assignment whenyou finish![ ]:# When you log-in please hit return (not shift + return) after typing in your,email_=ok.submit()1
Background image
1.11. Creating ArraysQuestion 1.Make an array calledweird_numberscontaining the following numbers (in the givenorder):1. -22. the sine of 1.23. 34. 5 to the power of the cosine of 1.2Hint:sinandcosare functions in themathmodule.BEGIN QUESTIONname: q1_1[2]:# Our solution involved one extra line of code before creating# weird_numbers.importmath#SOLUTIONweird_numbers=make_array(-2, math.sin(1.2),3,5**math.cos(1.2))#SOLUTIONweird_numbers[2]:array([-2.,0.93203909,3.,1.79174913])[3]:# TESTnp.allclose(weird_numbers, np.array([-2.,0.93203909,3.,1.79174913]),,rtol=1e-03, atol=1e-03)[3]:TrueQuestion 2.Make an array calledbook_title_wordscontaining the following three strings:”Eats”, ”Shoots”, and ”and Leaves”.BEGIN QUESTIONname: q1_2[4]:book_title_words=make_array("Eats","Shoots","and Leaves")#SOLUTIONbook_title_words[4]:array(['Eats', 'Shoots', 'and Leaves'], dtype='<U10')Strings have a method calledjoin.jointakes one argument, an array of strings.It returnsa single string.Specifically, the value ofa_string.join(an_array)is a single string that’s theconcatenation(”putting together”) of all the strings inan_array,excepta_stringis inserted inbetween each string.
Background image
Image of page 3

You've reached the end of your free preview.

Want to read all 13 pages?

  • Fall '17

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors