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...

• Homework Help
• 13
• 100% (7) 7 out of 7 people found this document helpful

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

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.

#### You've reached the end of your free preview.

Want to read all 13 pages?

• Fall '17

### What students are saying

• 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.

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

• 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.

Dana University of Pennsylvania ‘17, Course Hero Intern

• 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.

Jill Tulane University ‘16, Course Hero Intern