Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

VOCABULARY

Rating
-
Sold
-
Pages
17
Grade
A+
Uploaded on
14-02-2022
Written in
2021/2022

Exam of 17 pages for the course DATA DATA8 at DATA DATA8 (VOCABULARY)

Institution
Course

Content preview

hw02


September 16, 2018


1 Homework 2: Arrays and Tables
Recommended Reading: * Data Types * Sequences * Tables.
Please complete this notebook by filling in the cells provided. Before you begin, execute the
following cell to load the provided tests. Each time you start your server, you will need to execute
this cell again to load the tests.
Homework 2 is due Thursday, 9/6 at 11:59pm. Start early so that you can come to office
hours if you’re stuck. Check the website for the office hours schedule. You will receive an early
submission bonus point if you turn in your final submission by Wednesday, 9/5 at 11:59pm. Late
work will not be accepted as per the policies of this course.
Throughout this homework and all future ones, please be sure to not re-assign variables
throughout the notebook! For example, if you use max_temperature in your answer to one ques-
tion, do not reassign it later on.

In [1]: # Don't change this cell; just run it.

import numpy as np
from datascience import *

from client.api.notebook import Notebook
ok = Notebook('hw02.ok')
_ = ok.auth(inline=True)

=====================================================================
Assignment: Homework 2: Arrays and Tables
OK, version v1.12.5
=====================================================================

Successfully logged in as


Important: In this homework, the ok tests will tell you whether your answer is correct, ex-
cept for Parts 4, 5 & 6. In future homework assignments, correctness tests will typically not be
provided.

In [ ]:




1

,1.1 1. Creating Arrays
Question 1. Make an array called weird_numbers containing the following numbers (in the given
order):
1. -2
2. the sine of 1.2
3. 3
4. 5 to the power of the cosine of 1.2
Hint: sin and cos are functions in the math module.
In [2]: # Our solution involved one extra line of code before creating
# weird_numbers.
import math
weird_numbers = make_array(-2, math.sin(1.2), 3, 5**(math.cos(1.2)))
weird_numbers
Out[2]: array([-2. , 0.93203909, 3. , 1.79174913])
In [3]: _ = ok.grade('q1_1')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Running tests

---------------------------------------------------------------------
Test summary
Passed: 1
Failed: 0
[ooooooooook] 100.0% passed



Question 2. Make an array called book_title_words containing the following three strings:
"Eats", "Shoots", and "and Leaves".
In [6]: book_title_words = make_array('Eats','Shoots','and Leaves')
book_title_words
Out[6]: array(['Eats', 'Shoots', 'and Leaves'], dtype='<U10')
In [7]: _ = ok.grade('q1_2')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Running tests

---------------------------------------------------------------------
Test summary
Passed: 7
Failed: 0
[ooooooooook] 100.0% passed




2

, Strings have a method called join. join takes one argument, an array of strings. It returns
a single string. Specifically, the value of a_string.join(an_array) is a single string that’s the
concatenation ("putting together") of all the strings in an_array, except a_string is inserted in
between each string.
Question 3. Use the array book_title_words and the method join to make two strings:

1. "Eats, Shoots, and Leaves" (call this one with_commas)
2. "Eats Shoots and Leaves" (call this one without_commas)

Hint: If you’re not sure what join does, first try just calling, for example,
"foo".join(book_title_words) .

In [18]: with_commas = ", ".join(book_title_words)
without_commas = " ".join(book_title_words)

# These lines are provided just to print out your answers.
print('with_commas:', with_commas)
print('without_commas:', without_commas)

with_commas: Eats, Shoots, and Leaves
without_commas: Eats Shoots and Leaves


In [19]: _ = ok.grade('q1_3')

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Running tests

---------------------------------------------------------------------
Test summary
Passed: 1
Failed: 0
[ooooooooook] 100.0% passed




1.2 2. Indexing Arrays
These exercises give you practice accessing individual elements of arrays. In Python (and in many
programming languages), elements are accessed by index, so the first element is the element at
index 0.
Question 1. The cell below creates an array of some numbers. Set third_element to the third
element of some_numbers.

In [21]: some_numbers = make_array(-1, -3, -6, -10, -15)

third_element = some_numbers.item(2)
third_element

Out[21]: -6

3

Written for

Course

Document information

Uploaded on
February 14, 2022
Number of pages
17
Written in
2021/2022
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
gersro

Get to know the seller

Seller avatar
gersro Arizona Medical Training Institute
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
13
Last sold
-
MEDLUXT IMPEX

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions