-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy_of_intro_to_python_ii.py
113 lines (75 loc) · 3.13 KB
/
copy_of_intro_to_python_ii.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# -*- coding: utf-8 -*-
"""Copy of Intro_to_Python_II.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1sboWU3dUWZ2iCb4Ylxy06EFgdMSyNjEf
# **Lab 2 - Introduction to Python programming II**
Enter your code in the spaces provided. Do not change any of the variable names or function names that are already provided for you. In places where we specify the name of the return value, make sure that your code produces the a value with the correct name.
"""
# Do not edit this cell.
LabID="Lab2"
try:
from graderHelp import ISGRADEPLOT
except ImportError:
ISGRADEPLOT = True
"""**Enter your name, section number, and BYU NetID**"""
# Enter your first and last names in between the quotation marks.
first_name="Madison"
last_name="Wozniak"
# Enter your Math 215 section number in between the quotation marks.
section_number="001"
# Enter your BYU NetID in between the quotation marks. NOT YOUR BYU ID NUMBER!
BYUNetID="mwozniak"
"""**Problem 1**"""
first_elem=1 # Replace the value of 0 with the number described in Problem 1.
"""**Problem 2**"""
def sum_list(L):
sum=0
for i in L:
sum+=i
return sum
L=[1,2,3,4]
sum_list(L) # Put your return value here.
"""**Problem 3**"""
def list_relu(L):
new_list=L.copy() # Remember to create a copy of your list. After this lab you'll need to remember to do it on your own.
for i in range(len(new_list)):
if new_list[i]<0:
new_list[i]=0
return new_list
list_relu([1,-2,17,-3.2,-15])
"""**Problem 4**"""
import numpy as np # Importing NumPy
my_var= (np.exp(5)-np.log(np.sqrt(5)))/(np.exp(np.cos(3)))
my_var
"""**Problem 5**"""
v=np.array([1,3,-2,4,5])
u=np.array([1,1,-2,1,1])
w=np.array([1,0,1,0,1])
my_vect_var=((np.dot(v,u))/(np.dot(u,u)))*u+((np.dot(v,w))/(np.dot(w,w)))*w
my_vect_var
"""**Problem 6**"""
def first_rpt(M):
new_matrix=M.copy()
for i in range(len(new_matrix)):
new_matrix[i]=new_matrix[0]
return new_matrix
Matrix=np.array([[1,2,3],[6,6,6],[4,4,4]])
first_rpt(Matrix)
"""**Problem 7**"""
def matrix_sum(M):
n_rows=len(M)
n_cols=len(M[0,:])
sum=0
for num in range(n_rows):
for num2 in range(n_cols):
sum += M[num][num2]
return sum
"""**Problem 8**"""
long_list= [0.5**j for j in range(1,101)]
"""**Problem 9**"""
very_long_list= [i**j for j in range(1,100) for i in range(1,4)]
"""**STOP! BEFORE YOU SUBMIT THIS LAB:** Go to the "Runtime" menu at the top of this page, and select "Restart and run all". If any of the cells produce error messages, you will either need to fix the error(s) or delete the code that is causing the error(s). Then use "Restart and run all" again to see if there are any new errors. Repeat this until no new error messages show up.
**You are not ready to submit until you are able to select "Restart and run all" without any new error messages showing up. Your code will not be able to be graded if there are any error messages.**
To submit your lab for grading you must first download it to your compute as .py file. In the "File" menu select "Download .py". The resulting file can then be uploaded to http://www.math.byu.edu:30000 for grading.
"""