forked from mathurinm/github-assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
numpy_questions.py
67 lines (52 loc) · 1.82 KB
/
numpy_questions.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
"""Assignment - using numpy and making a PR.
The goals of this assignment are:
* Use numpy in practice with two easy exercises.
* Use automated tools to validate the code (`pytest` and `flake8`)
* Submit a Pull-Request on github to practice `git`.
The two functions below are skeleton functions. The docstrings explain what
are the inputs, the outputs and the expected error. Fill the function to
complete the assignment. The code should be able to pass the test that we
wrote. To run the tests, use `pytest test_numpy_question.py` at the root of
the repo. It should say that 2 tests ran with success.
We also ask to respect the pep8 convention: https://pep8.org.
This will be enforced with `flake8`. You can check that there is no flake8
errors by calling `flake8` at the root of the repo.
"""
import numpy as np
def max_index(X):
"""Return the index of the maximum in a numpy array.
Parameters
----------
X : ndarray of shape (n_samples, n_features)
The input array.
Returns
-------
(i, j) : tuple(int)
The row and columnd index of the maximum.
Raises
------
ValueError
If the input is not a numpy array or
if the shape is not 2D.
"""
i = 0
j = 0
# TODO
return i, j
def wallis_product(n_terms):
"""Implement the Wallis product to compute an approximation of pi.
See:
https://en.wikipedia.org/wiki/Wallis_product
Parameters
----------
n_terms : int
Number of steps in the Wallis product. Note that `n_terms=0` will
consider the product to be `1`.
Returns
-------
pi : float
The approximation of order `n_terms` of pi using the Wallis product.
"""
# XXX : The n_terms is an int that corresponds to the number of
# terms in the product. For example 10000.
return 0.