-
Notifications
You must be signed in to change notification settings - Fork 14
/
assessment.py
142 lines (108 loc) · 3.76 KB
/
assessment.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import numpy as np
import pandas as pd
# PYTHON SECTION
def count_characters(string):
'''
INPUT: STRING
OUTPUT: DICT (with counts of each character in input string)
Return a dictionary which contains
a count of the number of times each character appears in the string.
Characters which with a count of 0 should not be included in the
output dictionary.
'''
pass
def invert_dictionary(d):
'''
INPUT: DICT
OUTPUT: DICT (of sets of input keys indexing the same input values
indexed by the input values)
Given a dictionary d, return a new dictionary with d's values
as keys and the value for a given key being
the set of d's keys which shared the same value.
e.g. {'a': 2, 'b': 4, 'c': 2} => {2: {'a', 'c'}, 4: {'b'}}
'''
pass
def word_count(filename):
'''
INPUT: STRING
OUTPUT: INT, INT, INT (a tuple with line, word,
and character count of named INPUT file)
The INPUT filename is the name of a text file.
The OUTPUT is a tuple containting (in order)
the following stats for the text file:
1. number of lines
2. number of words (broken by whitespace)
3. number of characters
'''
pass
def matrix_multiplication(A, B):
'''
INPUT: LIST (of length n) OF LIST (of length n) OF INTEGERS,
LIST (of length n) OF LIST (of length n) OF INTEGERS
OUTPUT: LIST OF LIST OF INTEGERS
(storing the product of a matrix multiplication operation)
Return the matrix which is the product of matrix A and matrix B
where A and B will be (a) integer valued (b) square matrices
(c) of size n-by-n (d) encoded as lists of lists.
For example:
A = [[2, 3, 4], [6, 4, 2], [-1, 2, 0]] corresponds to the matrix
| 2 3 4 |
| 6 4 2 |
|-1 2 0 |
Please do not use numpy. Write your solution in straight python.
'''
pass
# NumPy SECTION
def array_work(rows, cols, scalar, matrixA):
'''
INPUT: INT, INT, INT, NUMPY ARRAY
OUTPUT: NUMPY ARRAY
(of matrix product of r-by-c matrix of "scalar"'s time matrixA)
Create matrix of size (rows, cols) with elements initialized to the scalar
value. Right multiply that matrix with the passed matrixA (i.e. AB, not
BA). Return the result of the multiplication. You needn't check for
matrix compatibililty, but you accomplish this in a single line.
E.g., array_work(2, 3, 5, [[3, 4], [5, 6], [7, 8]])
[[3, 4], [[5, 5, 5],
[5, 6], * [5, 5, 5]]
[7, 8]]
'''
pass
def boolean_indexing(arr, minimum):
'''
INPUT: NUMPY ARRAY, INT
OUTPUT: NUMPY ARRAY
(of just elements in "arr" greater or equal to "minimum")
Return an array of only the elements of "arr" that are greater than or
equal to "minimum"
Ex:
In [1]: boolean_indexing([[3, 4, 5], [6, 7, 8]], 7)
Out[1]: array([7, 8])
'''
pass
# Pandas SECTION
def make_series(start, length, index):
'''
INPUTS: INT, INT, LIST (of length "length")
OUTPUT: PANDAS SERIES (of "length" sequential integers
beginning with "start" and with index "index")
Create a pandas Series of length "length" with index "index"
and with elements that are sequential integers starting from "start".
You may assume the length of index will be "length".
E.g.,
In [1]: make_series(5, 3, ['a', 'b', 'c'])
Out[1]:
a 5
b 6
c 7
dtype: int64
'''
pass
def data_frame_work(df, colA, colB, colC):
'''
INPUT: DATAFRAME, STR, STR, STR
OUTPUT: None
Insert a column (colC) into the dataframe that is the sum of colA and colB.
Assume that df contains columns colA and colB and that these are numeric.
'''
pass