Skip to content

Commit 0a8c086

Browse files
committed
Fix some more numpy tests
1 parent bc5abfd commit 0a8c086

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

fractals/julia_sets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
def eval_exponential(c_parameter: complex, z_values: np.ndarray) -> np.ndarray:
4141
"""
4242
Evaluate $e^z + c$.
43-
>>> float(eval_exponential(0, 0))
43+
>>> eval_exponential(0, 0)
4444
1.0
45-
>>> bool(abs(eval_exponential(1, np.pi*1.j)) < 1e-15)
45+
>>> abs(eval_exponential(1, np.pi*1.j)) < 1e-15
4646
True
47-
>>> bool(abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15)
47+
>>> abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15
4848
True
4949
"""
5050
return np.exp(z_values) + c_parameter
@@ -101,17 +101,17 @@ def iterate_function(
101101
>>> np.round(iterate_function(eval_quadratic_polynomial,
102102
... 0,
103103
... 3,
104-
... complex(np.array([0,1,2]))[0]))
104+
... np.array([0,1,2]))[0])
105105
0j
106106
>>> np.round(iterate_function(eval_quadratic_polynomial,
107107
... 0,
108108
... 3,
109-
... complex(np.array([0,1,2]))[1]))
109+
... np.array([0,1,2]))[1])
110110
(1+0j)
111111
>>> np.round(iterate_function(eval_quadratic_polynomial,
112112
... 0,
113113
... 3,
114-
... complex(np.array([0,1,2]))[2]))
114+
... np.array([0,1,2]))[2])
115115
(256+0j)
116116
"""
117117

machine_learning/k_nearest_neighbours.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def _euclidean_distance(a: np.ndarray[float], b: np.ndarray[float]) -> float:
4242
>>> KNN._euclidean_distance(np.array([1, 2, 3]), np.array([1, 8, 11]))
4343
10.0
4444
"""
45-
return np.linalg.norm(a - b)
45+
return float(np.linalg.norm(a - b))
4646

4747
def classify(self, pred_point: np.ndarray[float], k: int = 5) -> str:
4848
"""

machine_learning/logistic_regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def sigmoid_function(z: float | np.ndarray) -> float | np.ndarray:
4545
@returns: returns value in the range 0 to 1
4646
4747
Examples:
48-
>>> sigmoid_function(4)
48+
>>> float(sigmoid_function(4))
4949
0.9820137900379085
5050
>>> sigmoid_function(np.array([-3, 3]))
5151
array([0.04742587, 0.95257413])
@@ -100,7 +100,7 @@ def cost_function(h: np.ndarray, y: np.ndarray) -> float:
100100
References:
101101
- https://en.wikipedia.org/wiki/Logistic_regression
102102
"""
103-
return (-y * np.log(h) - (1 - y) * np.log(1 - h)).mean()
103+
return float((-y * np.log(h) - (1 - y) * np.log(1 - h)).mean())
104104

105105

106106
def log_likelihood(x, y, weights):

maths/numerical_analysis/runge_kutta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def runge_kutta(f, y0, x0, h, x_end):
1919
... return y
2020
>>> y0 = 1
2121
>>> y = runge_kutta(f, y0, 0.0, 0.01, 5)
22-
>>> y[-1]
22+
>>> float(y[-1])
2323
148.41315904125113
2424
"""
2525
n = int(np.ceil((x_end - x0) / h))

other/bankers_algorithm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __need_index_manager(self) -> dict[int, list[int]]:
9393
{0: [1, 2, 0, 3], 1: [0, 1, 3, 1], 2: [1, 1, 0, 2], 3: [1, 3, 2, 0],
9494
4: [2, 0, 0, 3]}
9595
"""
96-
return {self.__need().index(i): int(i) for i in self.__need()}
96+
return {self.__need().index(i): i for i in self.__need()}
9797

9898
def main(self, **kwargs) -> None:
9999
"""

0 commit comments

Comments
 (0)