File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -41,9 +41,24 @@ def max_index(X):
41
41
j = 0
42
42
43
43
# TODO
44
+ if isinstance (X , np .ndarray ) == False :
45
+ raise ValueError ("The input is not a numpy array" )
46
+
47
+ elif X .ndim != 2 :
48
+ raise ValueError ("The shape is not 2D" )
49
+
50
+ else :
51
+ for row in range (X .shape [0 ]):
52
+ for col in range (X .shape [1 ]):
53
+ if X [row , col ] > X [i , j ]:
54
+ i = row
55
+ j = col
44
56
45
57
return i , j
46
58
59
+ # X = np.array([[1,2],[3,4]])
60
+ # print("X", max_index(X))
61
+
47
62
48
63
def wallis_product (n_terms ):
49
64
"""Implement the Wallis product to compute an approximation of pi.
@@ -64,4 +79,5 @@ def wallis_product(n_terms):
64
79
"""
65
80
# XXX : The n_terms is an int that corresponds to the number of
66
81
# terms in the product. For example 10000.
67
- return 0.
82
+
83
+ return 2 * np .prod ([(4 * i ** 2 ) / (4 * i ** 2 - 1 ) for i in range (1 , n_terms + 1 )])
You can’t perform that action at this time.
0 commit comments