forked from wmvanvliet/gizmo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgizmo.py
107 lines (77 loc) · 2.33 KB
/
gizmo.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
GIZMO Challenge
@author: [email protected]
@version: 20210319
@notes: Funfunfun!
"""
import numpy as np
import pandas as pd
# -------------------- Exercise 1 --------------------
def hello(name, country='Finland'):
print('Hello ' + name + ', how are things in ' + country + '?')
# -------------------- Exercise 2 --------------------
def spell(name):
out = ''
for i in range(len(name)):
out = out + name[i] + '.'
print(out[:-1])
# -------------------- Exercise 3 --------------------
def relative_path(ids):
base = ['./subjects/mock_recording_','.rec']
names = []
if type(ids) == str:
ids = [ids]
for s in ids:
names.append(base[0] + s + base[1])
return names
# ------------------- Exercise 4–7 --------------------
class Gizmo:
def __init__(self, name):
self.name = name
def speak(self):
print(self.name)
# ------------------- Exercise 8-9 --------------------
def multiplication_table(zero_out_multiples=None):
"""Times table with optional dropping of multiples
Returns the times table for integers up to 12, and optionally
zeroes the multiples of the given int argument.
Parameters
----------
zom : int, optional
The integer to drop the multiples of (zero_out_multiples)
Returns
-------
tab : numpy array
The times table as an array
"""
v = np.arange(1,13)
tab = np.outer(v,v)
if type(zero_out_multiples) == int:
tab[tab%zero_out_multiples == 0] = 0
return tab
# ------------------- Exercise 11 --------------------
def generate_fibonacci_sequence(n):
first=0
second=1
for i in range(n):
yield first
third = first+second
first = second
second = third
# ------------------- Exercise 12 --------------------
def get_fibonacci_sequence(n):
fib = generate_fibonacci_sequence(n)
arr = np.empty(0)
for f in fib:
arr = np.append(arr,f)
return arr
# ------------------- Exercise 13 --------------------
def get_titanic():
df = pd.read_csv('titanic.csv')
return df
# ------------------- Exercise 14 --------------------
def get_titanic_children(age=12):
df = get_titanic()
return df.query('age <= @age')