Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0177ae1

Browse files
authoredSep 30, 2024
Upgrade to Python 3.13 (TheAlgorithms#11588)
1 parent a7bfa22 commit 0177ae1

35 files changed

+135
-131
lines changed
 

‎.github/workflows/build.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
- uses: actions/checkout@v4
1313
- uses: actions/setup-python@v5
1414
with:
15-
python-version: 3.12
15+
python-version: 3.13
1616
allow-prereleases: true
1717
- uses: actions/cache@v4
1818
with:
@@ -26,6 +26,10 @@ jobs:
2626
# TODO: #8818 Re-enable quantum tests
2727
run: pytest
2828
--ignore=quantum/q_fourier_transform.py
29+
--ignore=computer_vision/cnn_classification.py
30+
--ignore=dynamic_programming/k_means_clustering_tensorflow.py
31+
--ignore=machine_learning/lstm/lstm_prediction.py
32+
--ignore=neural_network/input_data.py
2933
--ignore=project_euler/
3034
--ignore=scripts/validate_solutions.py
3135
--cov-report=term-missing:skip-covered

‎DIRECTORY.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,6 @@
13431343
* [Get Ip Geolocation](web_programming/get_ip_geolocation.py)
13441344
* [Get Top Billionaires](web_programming/get_top_billionaires.py)
13451345
* [Get Top Hn Posts](web_programming/get_top_hn_posts.py)
1346-
* [Get User Tweets](web_programming/get_user_tweets.py)
13471346
* [Giphy](web_programming/giphy.py)
13481347
* [Instagram Crawler](web_programming/instagram_crawler.py)
13491348
* [Instagram Pic](web_programming/instagram_pic.py)

‎computer_vision/haralick_descriptors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def root_mean_square_error(original: np.ndarray, reference: np.ndarray) -> float
1919
>>> root_mean_square_error(np.array([1, 2, 3]), np.array([6, 4, 2]))
2020
3.1622776601683795
2121
"""
22-
return np.sqrt(((original - reference) ** 2).mean())
22+
return float(np.sqrt(((original - reference) ** 2).mean()))
2323

2424

2525
def normalize_image(
@@ -273,7 +273,7 @@ def haralick_descriptors(matrix: np.ndarray) -> list[float]:
273273
>>> morphological = opening_filter(binary)
274274
>>> mask_1 = binary_mask(gray, morphological)[0]
275275
>>> concurrency = matrix_concurrency(mask_1, (0, 1))
276-
>>> haralick_descriptors(concurrency)
276+
>>> [float(f) for f in haralick_descriptors(concurrency)]
277277
[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
278278
"""
279279
# Function np.indices could be used for bigger input types,
@@ -335,7 +335,7 @@ def get_descriptors(
335335
return np.concatenate(descriptors, axis=None)
336336

337337

338-
def euclidean(point_1: np.ndarray, point_2: np.ndarray) -> np.float32:
338+
def euclidean(point_1: np.ndarray, point_2: np.ndarray) -> float:
339339
"""
340340
Simple method for calculating the euclidean distance between two points,
341341
with type np.ndarray.
@@ -346,7 +346,7 @@ def euclidean(point_1: np.ndarray, point_2: np.ndarray) -> np.float32:
346346
>>> euclidean(a, b)
347347
3.3166247903554
348348
"""
349-
return np.sqrt(np.sum(np.square(point_1 - point_2)))
349+
return float(np.sqrt(np.sum(np.square(point_1 - point_2))))
350350

351351

352352
def get_distances(descriptors: np.ndarray, base: int) -> list[tuple[int, float]]:

‎data_structures/heap/binomial_heap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BinomialHeap:
7373
30
7474
7575
Deleting - delete() test
76-
>>> [first_heap.delete_min() for _ in range(20)]
76+
>>> [int(first_heap.delete_min()) for _ in range(20)]
7777
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
7878
7979
Create a new Heap
@@ -118,7 +118,7 @@ class BinomialHeap:
118118
values in merged heap; (merge is inplace)
119119
>>> results = []
120120
>>> while not first_heap.is_empty():
121-
... results.append(first_heap.delete_min())
121+
... results.append(int(first_heap.delete_min()))
122122
>>> results
123123
[17, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 34]
124124
"""
@@ -354,7 +354,7 @@ def delete_min(self):
354354
# Merge heaps
355355
self.merge_heaps(new_heap)
356356

357-
return min_value
357+
return int(min_value)
358358

359359
def pre_order(self):
360360
"""

‎electronics/circular_convolution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def circular_convolution(self) -> list[float]:
3939
Usage:
4040
>>> convolution = CircularConvolution()
4141
>>> convolution.circular_convolution()
42-
[10, 10, 6, 14]
42+
[10.0, 10.0, 6.0, 14.0]
4343
4444
>>> convolution.first_signal = [0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.4, 1.6]
4545
>>> convolution.second_signal = [0.1, 0.3, 0.5, 0.7, 0.9, 1.1, 1.3, 1.5]
@@ -54,7 +54,7 @@ def circular_convolution(self) -> list[float]:
5454
>>> convolution.first_signal = [1, -1, 2, 3, -1]
5555
>>> convolution.second_signal = [1, 2, 3]
5656
>>> convolution.circular_convolution()
57-
[8, -2, 3, 4, 11]
57+
[8.0, -2.0, 3.0, 4.0, 11.0]
5858
5959
"""
6060

@@ -91,7 +91,7 @@ def circular_convolution(self) -> list[float]:
9191
final_signal = np.matmul(np.transpose(matrix), np.transpose(self.first_signal))
9292

9393
# rounding-off to two decimal places
94-
return [round(i, 2) for i in final_signal]
94+
return [float(round(i, 2)) for i in final_signal]
9595

9696

9797
if __name__ == "__main__":

‎fractals/julia_sets.py

Lines changed: 9 additions & 9 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-
>>> eval_exponential(0, 0)
43+
>>> float(eval_exponential(0, 0))
4444
1.0
45-
>>> abs(eval_exponential(1, np.pi*1.j)) < 1e-15
45+
>>> bool(abs(eval_exponential(1, np.pi*1.j)) < 1e-15)
4646
True
47-
>>> abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15
47+
>>> bool(abs(eval_exponential(1.j, 0)-1-1.j) < 1e-15)
4848
True
4949
"""
5050
return np.exp(z_values) + c_parameter
@@ -98,20 +98,20 @@ def iterate_function(
9898
9999
>>> iterate_function(eval_quadratic_polynomial, 0, 3, np.array([0,1,2])).shape
100100
(3,)
101-
>>> np.round(iterate_function(eval_quadratic_polynomial,
101+
>>> complex(np.round(iterate_function(eval_quadratic_polynomial,
102102
... 0,
103103
... 3,
104-
... np.array([0,1,2]))[0])
104+
... np.array([0,1,2]))[0]))
105105
0j
106-
>>> np.round(iterate_function(eval_quadratic_polynomial,
106+
>>> complex(np.round(iterate_function(eval_quadratic_polynomial,
107107
... 0,
108108
... 3,
109-
... np.array([0,1,2]))[1])
109+
... np.array([0,1,2]))[1]))
110110
(1+0j)
111-
>>> np.round(iterate_function(eval_quadratic_polynomial,
111+
>>> complex(np.round(iterate_function(eval_quadratic_polynomial,
112112
... 0,
113113
... 3,
114-
... np.array([0,1,2]))[2])
114+
... np.array([0,1,2]))[2]))
115115
(256+0j)
116116
"""
117117

‎graphics/bezier_curve.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ def basis_function(self, t: float) -> list[float]:
3030
returns the x, y values of basis function at time t
3131
3232
>>> curve = BezierCurve([(1,1), (1,2)])
33-
>>> curve.basis_function(0)
33+
>>> [float(x) for x in curve.basis_function(0)]
3434
[1.0, 0.0]
35-
>>> curve.basis_function(1)
35+
>>> [float(x) for x in curve.basis_function(1)]
3636
[0.0, 1.0]
3737
"""
3838
assert 0 <= t <= 1, "Time t must be between 0 and 1."
@@ -55,9 +55,9 @@ def bezier_curve_function(self, t: float) -> tuple[float, float]:
5555
The last point in the curve is when t = 1.
5656
5757
>>> curve = BezierCurve([(1,1), (1,2)])
58-
>>> curve.bezier_curve_function(0)
58+
>>> tuple(float(x) for x in curve.bezier_curve_function(0))
5959
(1.0, 1.0)
60-
>>> curve.bezier_curve_function(1)
60+
>>> tuple(float(x) for x in curve.bezier_curve_function(1))
6161
(1.0, 2.0)
6262
"""
6363

‎graphs/dijkstra_binary_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def dijkstra(
6969
x, y = predecessors[x, y]
7070
path.append(source) # add the source manually
7171
path.reverse()
72-
return matrix[destination], path
72+
return float(matrix[destination]), path
7373

7474
for i in range(len(dx)):
7575
nx, ny = x + dx[i], y + dy[i]

‎linear_algebra/src/power_iteration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def power_iteration(
7878
if is_complex:
7979
lambda_ = np.real(lambda_)
8080

81-
return lambda_, vector
81+
return float(lambda_), vector
8282

8383

8484
def test_power_iteration() -> None:

‎linear_programming/simplex.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ def generate_col_titles(self) -> list[str]:
107107

108108
def find_pivot(self) -> tuple[Any, Any]:
109109
"""Finds the pivot row and column.
110-
>>> Tableau(np.array([[-2,1,0,0,0], [3,1,1,0,6], [1,2,0,1,7.]]),
111-
... 2, 0).find_pivot()
110+
>>> tuple(int(x) for x in Tableau(np.array([[-2,1,0,0,0], [3,1,1,0,6],
111+
... [1,2,0,1,7.]]), 2, 0).find_pivot())
112112
(1, 0)
113113
"""
114114
objective = self.objectives[-1]
@@ -215,56 +215,56 @@ def run_simplex(self) -> dict[Any, Any]:
215215
Max: x1 + x2
216216
ST: x1 + 3x2 <= 4
217217
3x1 + x2 <= 4
218-
>>> Tableau(np.array([[-1,-1,0,0,0],[1,3,1,0,4],[3,1,0,1,4.]]),
219-
... 2, 0).run_simplex()
218+
>>> {key: float(value) for key, value in Tableau(np.array([[-1,-1,0,0,0],
219+
... [1,3,1,0,4],[3,1,0,1,4.]]), 2, 0).run_simplex().items()}
220220
{'P': 2.0, 'x1': 1.0, 'x2': 1.0}
221221
222222
# Standard linear program with 3 variables:
223223
Max: 3x1 + x2 + 3x3
224224
ST: 2x1 + x2 + x3 ≤ 2
225225
x1 + 2x2 + 3x3 ≤ 5
226226
2x1 + 2x2 + x3 ≤ 6
227-
>>> Tableau(np.array([
227+
>>> {key: float(value) for key, value in Tableau(np.array([
228228
... [-3,-1,-3,0,0,0,0],
229229
... [2,1,1,1,0,0,2],
230230
... [1,2,3,0,1,0,5],
231231
... [2,2,1,0,0,1,6.]
232-
... ]),3,0).run_simplex() # doctest: +ELLIPSIS
232+
... ]),3,0).run_simplex().items()} # doctest: +ELLIPSIS
233233
{'P': 5.4, 'x1': 0.199..., 'x3': 1.6}
234234
235235
236236
# Optimal tableau input:
237-
>>> Tableau(np.array([
237+
>>> {key: float(value) for key, value in Tableau(np.array([
238238
... [0, 0, 0.25, 0.25, 2],
239239
... [0, 1, 0.375, -0.125, 1],
240240
... [1, 0, -0.125, 0.375, 1]
241-
... ]), 2, 0).run_simplex()
241+
... ]), 2, 0).run_simplex().items()}
242242
{'P': 2.0, 'x1': 1.0, 'x2': 1.0}
243243
244244
# Non-standard: >= constraints
245245
Max: 2x1 + 3x2 + x3
246246
ST: x1 + x2 + x3 <= 40
247247
2x1 + x2 - x3 >= 10
248248
- x2 + x3 >= 10
249-
>>> Tableau(np.array([
249+
>>> {key: float(value) for key, value in Tableau(np.array([
250250
... [2, 0, 0, 0, -1, -1, 0, 0, 20],
251251
... [-2, -3, -1, 0, 0, 0, 0, 0, 0],
252252
... [1, 1, 1, 1, 0, 0, 0, 0, 40],
253253
... [2, 1, -1, 0, -1, 0, 1, 0, 10],
254254
... [0, -1, 1, 0, 0, -1, 0, 1, 10.]
255-
... ]), 3, 2).run_simplex()
255+
... ]), 3, 2).run_simplex().items()}
256256
{'P': 70.0, 'x1': 10.0, 'x2': 10.0, 'x3': 20.0}
257257
258258
# Non standard: minimisation and equalities
259259
Min: x1 + x2
260260
ST: 2x1 + x2 = 12
261261
6x1 + 5x2 = 40
262-
>>> Tableau(np.array([
262+
>>> {key: float(value) for key, value in Tableau(np.array([
263263
... [8, 6, 0, 0, 52],
264264
... [1, 1, 0, 0, 0],
265265
... [2, 1, 1, 0, 12],
266266
... [6, 5, 0, 1, 40.],
267-
... ]), 2, 2).run_simplex()
267+
... ]), 2, 2).run_simplex().items()}
268268
{'P': 7.0, 'x1': 5.0, 'x2': 2.0}
269269
270270
@@ -275,15 +275,15 @@ def run_simplex(self) -> dict[Any, Any]:
275275
2x1 + 4x2 <= 48
276276
x1 + x2 >= 10
277277
x1 >= 2
278-
>>> Tableau(np.array([
278+
>>> {key: float(value) for key, value in Tableau(np.array([
279279
... [2, 1, 0, 0, 0, -1, -1, 0, 0, 12.0],
280280
... [-8, -6, 0, 0, 0, 0, 0, 0, 0, 0.0],
281281
... [1, 3, 1, 0, 0, 0, 0, 0, 0, 33.0],
282282
... [4, 2, 0, 1, 0, 0, 0, 0, 0, 60.0],
283283
... [2, 4, 0, 0, 1, 0, 0, 0, 0, 48.0],
284284
... [1, 1, 0, 0, 0, -1, 0, 1, 0, 10.0],
285285
... [1, 0, 0, 0, 0, 0, -1, 0, 1, 2.0]
286-
... ]), 2, 2).run_simplex() # doctest: +ELLIPSIS
286+
... ]), 2, 2).run_simplex().items()} # doctest: +ELLIPSIS
287287
{'P': 132.0, 'x1': 12.000... 'x2': 5.999...}
288288
"""
289289
# Stop simplex algorithm from cycling.
@@ -307,11 +307,11 @@ def run_simplex(self) -> dict[Any, Any]:
307307
def interpret_tableau(self) -> dict[str, float]:
308308
"""Given the final tableau, add the corresponding values of the basic
309309
decision variables to the `output_dict`
310-
>>> Tableau(np.array([
310+
>>> {key: float(value) for key, value in Tableau(np.array([
311311
... [0,0,0.875,0.375,5],
312312
... [0,1,0.375,-0.125,1],
313313
... [1,0,-0.125,0.375,1]
314-
... ]),2, 0).interpret_tableau()
314+
... ]),2, 0).interpret_tableau().items()}
315315
{'P': 5.0, 'x1': 1.0, 'x2': 1.0}
316316
"""
317317
# P = RHS of final tableau

‎machine_learning/decision_tree.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ def mean_squared_error(self, labels, prediction):
2626
>>> tester = DecisionTree()
2727
>>> test_labels = np.array([1,2,3,4,5,6,7,8,9,10])
2828
>>> test_prediction = float(6)
29-
>>> tester.mean_squared_error(test_labels, test_prediction) == (
29+
>>> bool(tester.mean_squared_error(test_labels, test_prediction) == (
3030
... TestDecisionTree.helper_mean_squared_error_test(test_labels,
31-
... test_prediction))
31+
... test_prediction)))
3232
True
3333
>>> test_labels = np.array([1,2,3])
3434
>>> test_prediction = float(2)
35-
>>> tester.mean_squared_error(test_labels, test_prediction) == (
35+
>>> bool(tester.mean_squared_error(test_labels, test_prediction) == (
3636
... TestDecisionTree.helper_mean_squared_error_test(test_labels,
37-
... test_prediction))
37+
... test_prediction)))
3838
True
3939
"""
4040
if labels.ndim != 1:

‎machine_learning/forecasting/run.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def linear_regression_prediction(
2828
input : training data (date, total_user, total_event) in list of float
2929
output : list of total user prediction in float
3030
>>> n = linear_regression_prediction([2,3,4,5], [5,3,4,6], [3,1,2,4], [2,1], [2,2])
31-
>>> abs(n - 5.0) < 1e-6 # Checking precision because of floating point errors
31+
>>> bool(abs(n - 5.0) < 1e-6) # Checking precision because of floating point errors
3232
True
3333
"""
3434
x = np.array([[1, item, train_mtch[i]] for i, item in enumerate(train_dt)])
@@ -56,7 +56,7 @@ def sarimax_predictor(train_user: list, train_match: list, test_match: list) ->
5656
)
5757
model_fit = model.fit(disp=False, maxiter=600, method="nm")
5858
result = model_fit.predict(1, len(test_match), exog=[test_match])
59-
return result[0]
59+
return float(result[0])
6060

6161

6262
def support_vector_regressor(x_train: list, x_test: list, train_user: list) -> float:
@@ -75,7 +75,7 @@ def support_vector_regressor(x_train: list, x_test: list, train_user: list) -> f
7575
regressor = SVR(kernel="rbf", C=1, gamma=0.1, epsilon=0.1)
7676
regressor.fit(x_train, train_user)
7777
y_pred = regressor.predict(x_test)
78-
return y_pred[0]
78+
return float(y_pred[0])
7979

8080

8181
def interquartile_range_checker(train_user: list) -> float:
@@ -92,7 +92,7 @@ def interquartile_range_checker(train_user: list) -> float:
9292
q3 = np.percentile(train_user, 75)
9393
iqr = q3 - q1
9494
low_lim = q1 - (iqr * 0.1)
95-
return low_lim
95+
return float(low_lim)
9696

9797

9898
def data_safety_checker(list_vote: list, actual_result: float) -> bool:

‎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):

‎machine_learning/loss_functions.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def binary_cross_entropy(
2222
2323
>>> true_labels = np.array([0, 1, 1, 0, 1])
2424
>>> predicted_probs = np.array([0.2, 0.7, 0.9, 0.3, 0.8])
25-
>>> binary_cross_entropy(true_labels, predicted_probs)
25+
>>> float(binary_cross_entropy(true_labels, predicted_probs))
2626
0.2529995012327421
2727
>>> true_labels = np.array([0, 1, 1, 0, 1])
2828
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -68,7 +68,7 @@ def binary_focal_cross_entropy(
6868
6969
>>> true_labels = np.array([0, 1, 1, 0, 1])
7070
>>> predicted_probs = np.array([0.2, 0.7, 0.9, 0.3, 0.8])
71-
>>> binary_focal_cross_entropy(true_labels, predicted_probs)
71+
>>> float(binary_focal_cross_entropy(true_labels, predicted_probs))
7272
0.008257977659239775
7373
>>> true_labels = np.array([0, 1, 1, 0, 1])
7474
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -108,7 +108,7 @@ def categorical_cross_entropy(
108108
109109
>>> true_labels = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
110110
>>> pred_probs = np.array([[0.9, 0.1, 0.0], [0.2, 0.7, 0.1], [0.0, 0.1, 0.9]])
111-
>>> categorical_cross_entropy(true_labels, pred_probs)
111+
>>> float(categorical_cross_entropy(true_labels, pred_probs))
112112
0.567395975254385
113113
>>> true_labels = np.array([[1, 0], [0, 1]])
114114
>>> pred_probs = np.array([[0.9, 0.1, 0.0], [0.2, 0.7, 0.1]])
@@ -179,13 +179,13 @@ def categorical_focal_cross_entropy(
179179
>>> true_labels = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
180180
>>> pred_probs = np.array([[0.9, 0.1, 0.0], [0.2, 0.7, 0.1], [0.0, 0.1, 0.9]])
181181
>>> alpha = np.array([0.6, 0.2, 0.7])
182-
>>> categorical_focal_cross_entropy(true_labels, pred_probs, alpha)
182+
>>> float(categorical_focal_cross_entropy(true_labels, pred_probs, alpha))
183183
0.0025966118981496423
184184
185185
>>> true_labels = np.array([[0, 1, 0], [0, 0, 1]])
186186
>>> pred_probs = np.array([[0.05, 0.95, 0], [0.1, 0.8, 0.1]])
187187
>>> alpha = np.array([0.25, 0.25, 0.25])
188-
>>> categorical_focal_cross_entropy(true_labels, pred_probs, alpha)
188+
>>> float(categorical_focal_cross_entropy(true_labels, pred_probs, alpha))
189189
0.23315276982014324
190190
191191
>>> true_labels = np.array([[1, 0], [0, 1]])
@@ -265,7 +265,7 @@ def hinge_loss(y_true: np.ndarray, y_pred: np.ndarray) -> float:
265265
266266
>>> true_labels = np.array([-1, 1, 1, -1, 1])
267267
>>> pred = np.array([-4, -0.3, 0.7, 5, 10])
268-
>>> hinge_loss(true_labels, pred)
268+
>>> float(hinge_loss(true_labels, pred))
269269
1.52
270270
>>> true_labels = np.array([-1, 1, 1, -1, 1, 1])
271271
>>> pred = np.array([-4, -0.3, 0.7, 5, 10])
@@ -309,11 +309,11 @@ def huber_loss(y_true: np.ndarray, y_pred: np.ndarray, delta: float) -> float:
309309
310310
>>> true_values = np.array([0.9, 10.0, 2.0, 1.0, 5.2])
311311
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
312-
>>> np.isclose(huber_loss(true_values, predicted_values, 1.0), 2.102)
312+
>>> bool(np.isclose(huber_loss(true_values, predicted_values, 1.0), 2.102))
313313
True
314314
>>> true_labels = np.array([11.0, 21.0, 3.32, 4.0, 5.0])
315315
>>> predicted_probs = np.array([8.3, 20.8, 2.9, 11.2, 5.0])
316-
>>> np.isclose(huber_loss(true_labels, predicted_probs, 1.0), 1.80164)
316+
>>> bool(np.isclose(huber_loss(true_labels, predicted_probs, 1.0), 1.80164))
317317
True
318318
>>> true_labels = np.array([11.0, 21.0, 3.32, 4.0])
319319
>>> predicted_probs = np.array([8.3, 20.8, 2.9, 11.2, 5.0])
@@ -347,7 +347,7 @@ def mean_squared_error(y_true: np.ndarray, y_pred: np.ndarray) -> float:
347347
348348
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
349349
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
350-
>>> np.isclose(mean_squared_error(true_values, predicted_values), 0.028)
350+
>>> bool(np.isclose(mean_squared_error(true_values, predicted_values), 0.028))
351351
True
352352
>>> true_labels = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
353353
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -381,11 +381,11 @@ def mean_absolute_error(y_true: np.ndarray, y_pred: np.ndarray) -> float:
381381
382382
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
383383
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
384-
>>> np.isclose(mean_absolute_error(true_values, predicted_values), 0.16)
384+
>>> bool(np.isclose(mean_absolute_error(true_values, predicted_values), 0.16))
385385
True
386386
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
387387
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
388-
>>> np.isclose(mean_absolute_error(true_values, predicted_values), 2.16)
388+
>>> bool(np.isclose(mean_absolute_error(true_values, predicted_values), 2.16))
389389
False
390390
>>> true_labels = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
391391
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 5.2])
@@ -420,7 +420,7 @@ def mean_squared_logarithmic_error(y_true: np.ndarray, y_pred: np.ndarray) -> fl
420420
421421
>>> true_values = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
422422
>>> predicted_values = np.array([0.8, 2.1, 2.9, 4.2, 5.2])
423-
>>> mean_squared_logarithmic_error(true_values, predicted_values)
423+
>>> float(mean_squared_logarithmic_error(true_values, predicted_values))
424424
0.0030860877925181344
425425
>>> true_labels = np.array([1.0, 2.0, 3.0, 4.0, 5.0])
426426
>>> predicted_probs = np.array([0.3, 0.8, 0.9, 0.2])
@@ -459,17 +459,17 @@ def mean_absolute_percentage_error(
459459
Examples:
460460
>>> y_true = np.array([10, 20, 30, 40])
461461
>>> y_pred = np.array([12, 18, 33, 45])
462-
>>> mean_absolute_percentage_error(y_true, y_pred)
462+
>>> float(mean_absolute_percentage_error(y_true, y_pred))
463463
0.13125
464464
465465
>>> y_true = np.array([1, 2, 3, 4])
466466
>>> y_pred = np.array([2, 3, 4, 5])
467-
>>> mean_absolute_percentage_error(y_true, y_pred)
467+
>>> float(mean_absolute_percentage_error(y_true, y_pred))
468468
0.5208333333333333
469469
470470
>>> y_true = np.array([34, 37, 44, 47, 48, 48, 46, 43, 32, 27, 26, 24])
471471
>>> y_pred = np.array([37, 40, 46, 44, 46, 50, 45, 44, 34, 30, 22, 23])
472-
>>> mean_absolute_percentage_error(y_true, y_pred)
472+
>>> float(mean_absolute_percentage_error(y_true, y_pred))
473473
0.064671076436071
474474
"""
475475
if len(y_true) != len(y_pred):
@@ -511,7 +511,7 @@ def perplexity_loss(
511511
... [[0.03, 0.26, 0.21, 0.18, 0.30],
512512
... [0.28, 0.10, 0.33, 0.15, 0.12]]]
513513
... )
514-
>>> perplexity_loss(y_true, y_pred)
514+
>>> float(perplexity_loss(y_true, y_pred))
515515
5.0247347775367945
516516
>>> y_true = np.array([[1, 4], [2, 3]])
517517
>>> y_pred = np.array(
@@ -600,17 +600,17 @@ def smooth_l1_loss(y_true: np.ndarray, y_pred: np.ndarray, beta: float = 1.0) ->
600600
601601
>>> y_true = np.array([3, 5, 2, 7])
602602
>>> y_pred = np.array([2.9, 4.8, 2.1, 7.2])
603-
>>> smooth_l1_loss(y_true, y_pred, 1.0)
603+
>>> float(smooth_l1_loss(y_true, y_pred, 1.0))
604604
0.012500000000000022
605605
606606
>>> y_true = np.array([2, 4, 6])
607607
>>> y_pred = np.array([1, 5, 7])
608-
>>> smooth_l1_loss(y_true, y_pred, 1.0)
608+
>>> float(smooth_l1_loss(y_true, y_pred, 1.0))
609609
0.5
610610
611611
>>> y_true = np.array([1, 3, 5, 7])
612612
>>> y_pred = np.array([1, 3, 5, 7])
613-
>>> smooth_l1_loss(y_true, y_pred, 1.0)
613+
>>> float(smooth_l1_loss(y_true, y_pred, 1.0))
614614
0.0
615615
616616
>>> y_true = np.array([1, 3, 5])
@@ -647,7 +647,7 @@ def kullback_leibler_divergence(y_true: np.ndarray, y_pred: np.ndarray) -> float
647647
648648
>>> true_labels = np.array([0.2, 0.3, 0.5])
649649
>>> predicted_probs = np.array([0.3, 0.3, 0.4])
650-
>>> kullback_leibler_divergence(true_labels, predicted_probs)
650+
>>> float(kullback_leibler_divergence(true_labels, predicted_probs))
651651
0.030478754035472025
652652
>>> true_labels = np.array([0.2, 0.3, 0.5])
653653
>>> predicted_probs = np.array([0.3, 0.3, 0.4, 0.5])

‎machine_learning/mfcc.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ def normalize(audio: np.ndarray) -> np.ndarray:
162162
Examples:
163163
>>> audio = np.array([1, 2, 3, 4, 5])
164164
>>> normalized_audio = normalize(audio)
165-
>>> np.max(normalized_audio)
165+
>>> float(np.max(normalized_audio))
166166
1.0
167-
>>> np.min(normalized_audio)
167+
>>> float(np.min(normalized_audio))
168168
0.2
169169
"""
170170
# Divide the entire audio signal by the maximum absolute value
@@ -229,7 +229,8 @@ def calculate_fft(audio_windowed: np.ndarray, ftt_size: int = 1024) -> np.ndarra
229229
Examples:
230230
>>> audio_windowed = np.array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
231231
>>> audio_fft = calculate_fft(audio_windowed, ftt_size=4)
232-
>>> np.allclose(audio_fft[0], np.array([6.0+0.j, -1.5+0.8660254j, -1.5-0.8660254j]))
232+
>>> bool(np.allclose(audio_fft[0], np.array([6.0+0.j, -1.5+0.8660254j,
233+
... -1.5-0.8660254j])))
233234
True
234235
"""
235236
# Transpose the audio data to have time in rows and channels in columns
@@ -281,7 +282,7 @@ def freq_to_mel(freq: float) -> float:
281282
The frequency in mel scale.
282283
283284
Examples:
284-
>>> round(freq_to_mel(1000), 2)
285+
>>> float(round(freq_to_mel(1000), 2))
285286
999.99
286287
"""
287288
# Use the formula to convert frequency to the mel scale
@@ -321,7 +322,7 @@ def mel_spaced_filterbank(
321322
Mel-spaced filter bank.
322323
323324
Examples:
324-
>>> round(mel_spaced_filterbank(8000, 10, 1024)[0][1], 10)
325+
>>> float(round(mel_spaced_filterbank(8000, 10, 1024)[0][1], 10))
325326
0.0004603981
326327
"""
327328
freq_min = 0
@@ -438,7 +439,7 @@ def discrete_cosine_transform(dct_filter_num: int, filter_num: int) -> np.ndarra
438439
The DCT basis matrix.
439440
440441
Examples:
441-
>>> round(discrete_cosine_transform(3, 5)[0][0], 5)
442+
>>> float(round(discrete_cosine_transform(3, 5)[0][0], 5))
442443
0.44721
443444
"""
444445
basis = np.empty((dct_filter_num, filter_num))

‎machine_learning/multilayer_perceptron_classifier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
def wrapper(y):
1919
"""
20-
>>> wrapper(Y)
20+
>>> [int(x) for x in wrapper(Y)]
2121
[0, 0, 1]
2222
"""
2323
return list(y)

‎machine_learning/scoring_functions.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ def mae(predict, actual):
2020
"""
2121
Examples(rounded for precision):
2222
>>> actual = [1,2,3];predict = [1,4,3]
23-
>>> np.around(mae(predict,actual),decimals = 2)
23+
>>> float(np.around(mae(predict,actual),decimals = 2))
2424
0.67
2525
2626
>>> actual = [1,1,1];predict = [1,1,1]
27-
>>> mae(predict,actual)
27+
>>> float(mae(predict,actual))
2828
0.0
2929
"""
3030
predict = np.array(predict)
@@ -41,11 +41,11 @@ def mse(predict, actual):
4141
"""
4242
Examples(rounded for precision):
4343
>>> actual = [1,2,3];predict = [1,4,3]
44-
>>> np.around(mse(predict,actual),decimals = 2)
44+
>>> float(np.around(mse(predict,actual),decimals = 2))
4545
1.33
4646
4747
>>> actual = [1,1,1];predict = [1,1,1]
48-
>>> mse(predict,actual)
48+
>>> float(mse(predict,actual))
4949
0.0
5050
"""
5151
predict = np.array(predict)
@@ -63,11 +63,11 @@ def rmse(predict, actual):
6363
"""
6464
Examples(rounded for precision):
6565
>>> actual = [1,2,3];predict = [1,4,3]
66-
>>> np.around(rmse(predict,actual),decimals = 2)
66+
>>> float(np.around(rmse(predict,actual),decimals = 2))
6767
1.15
6868
6969
>>> actual = [1,1,1];predict = [1,1,1]
70-
>>> rmse(predict,actual)
70+
>>> float(rmse(predict,actual))
7171
0.0
7272
"""
7373
predict = np.array(predict)
@@ -84,12 +84,10 @@ def rmse(predict, actual):
8484
def rmsle(predict, actual):
8585
"""
8686
Examples(rounded for precision):
87-
>>> actual = [10,10,30];predict = [10,2,30]
88-
>>> np.around(rmsle(predict,actual),decimals = 2)
87+
>>> float(np.around(rmsle(predict=[10, 2, 30], actual=[10, 10, 30]), decimals=2))
8988
0.75
9089
91-
>>> actual = [1,1,1];predict = [1,1,1]
92-
>>> rmsle(predict,actual)
90+
>>> float(rmsle(predict=[1, 1, 1], actual=[1, 1, 1]))
9391
0.0
9492
"""
9593
predict = np.array(predict)
@@ -117,12 +115,12 @@ def mbd(predict, actual):
117115
118116
Here the model overpredicts
119117
>>> actual = [1,2,3];predict = [2,3,4]
120-
>>> np.around(mbd(predict,actual),decimals = 2)
118+
>>> float(np.around(mbd(predict,actual),decimals = 2))
121119
50.0
122120
123121
Here the model underpredicts
124122
>>> actual = [1,2,3];predict = [0,1,1]
125-
>>> np.around(mbd(predict,actual),decimals = 2)
123+
>>> float(np.around(mbd(predict,actual),decimals = 2))
126124
-66.67
127125
"""
128126
predict = np.array(predict)

‎machine_learning/similarity_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def cosine_similarity(input_a: np.ndarray, input_b: np.ndarray) -> float:
153153
>>> cosine_similarity(np.array([1, 2]), np.array([6, 32]))
154154
0.9615239476408232
155155
"""
156-
return np.dot(input_a, input_b) / (norm(input_a) * norm(input_b))
156+
return float(np.dot(input_a, input_b) / (norm(input_a) * norm(input_b)))
157157

158158

159159
if __name__ == "__main__":

‎machine_learning/support_vector_machines.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def norm_squared(vector: ndarray) -> float:
1414
Returns:
1515
float: squared second norm of vector
1616
17-
>>> norm_squared([1, 2])
17+
>>> int(norm_squared([1, 2]))
1818
5
19-
>>> norm_squared(np.asarray([1, 2]))
19+
>>> int(norm_squared(np.asarray([1, 2])))
2020
5
21-
>>> norm_squared([0, 0])
21+
>>> int(norm_squared([0, 0]))
2222
0
2323
"""
2424
return np.dot(vector, vector)

‎maths/euclidean_distance.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ def euclidean_distance(vector_1: Vector, vector_2: Vector) -> VectorOut:
1313
"""
1414
Calculate the distance between the two endpoints of two vectors.
1515
A vector is defined as a list, tuple, or numpy 1D array.
16-
>>> euclidean_distance((0, 0), (2, 2))
16+
>>> float(euclidean_distance((0, 0), (2, 2)))
1717
2.8284271247461903
18-
>>> euclidean_distance(np.array([0, 0, 0]), np.array([2, 2, 2]))
18+
>>> float(euclidean_distance(np.array([0, 0, 0]), np.array([2, 2, 2])))
1919
3.4641016151377544
20-
>>> euclidean_distance(np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8]))
20+
>>> float(euclidean_distance(np.array([1, 2, 3, 4]), np.array([5, 6, 7, 8])))
2121
8.0
22-
>>> euclidean_distance([1, 2, 3, 4], [5, 6, 7, 8])
22+
>>> float(euclidean_distance([1, 2, 3, 4], [5, 6, 7, 8]))
2323
8.0
2424
"""
2525
return np.sqrt(np.sum((np.asarray(vector_1) - np.asarray(vector_2)) ** 2))

‎maths/euler_method.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def explicit_euler(
2626
... return y
2727
>>> y0 = 1
2828
>>> y = explicit_euler(f, y0, 0.0, 0.01, 5)
29-
>>> y[-1]
29+
>>> float(y[-1])
3030
144.77277243257308
3131
"""
3232
n = int(np.ceil((x_end - x0) / step_size))

‎maths/euler_modified.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ def euler_modified(
2424
>>> def f1(x, y):
2525
... return -2*x*(y**2)
2626
>>> y = euler_modified(f1, 1.0, 0.0, 0.2, 1.0)
27-
>>> y[-1]
27+
>>> float(y[-1])
2828
0.503338255442106
2929
>>> import math
3030
>>> def f2(x, y):
3131
... return -2*y + (x**3)*math.exp(-2*x)
3232
>>> y = euler_modified(f2, 1.0, 0.0, 0.1, 0.3)
33-
>>> y[-1]
33+
>>> float(y[-1])
3434
0.5525976431951775
3535
"""
3636
n = int(np.ceil((x_end - x0) / step_size))

‎maths/gaussian.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@
55
from numpy import exp, pi, sqrt
66

77

8-
def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
8+
def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> float:
99
"""
10-
>>> gaussian(1)
10+
>>> float(gaussian(1))
1111
0.24197072451914337
1212
13-
>>> gaussian(24)
13+
>>> float(gaussian(24))
1414
3.342714441794458e-126
1515
16-
>>> gaussian(1, 4, 2)
16+
>>> float(gaussian(1, 4, 2))
1717
0.06475879783294587
1818
19-
>>> gaussian(1, 5, 3)
19+
>>> float(gaussian(1, 5, 3))
2020
0.05467002489199788
2121
2222
Supports NumPy Arrays
@@ -29,7 +29,7 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
2929
5.05227108e-15, 1.02797736e-18, 7.69459863e-23, 2.11881925e-27,
3030
2.14638374e-32, 7.99882776e-38, 1.09660656e-43])
3131
32-
>>> gaussian(15)
32+
>>> float(gaussian(15))
3333
5.530709549844416e-50
3434
3535
>>> gaussian([1,2, 'string'])
@@ -47,10 +47,10 @@ def gaussian(x, mu: float = 0.0, sigma: float = 1.0) -> int:
4747
...
4848
OverflowError: (34, 'Result too large')
4949
50-
>>> gaussian(10**-326)
50+
>>> float(gaussian(10**-326))
5151
0.3989422804014327
5252
53-
>>> gaussian(2523, mu=234234, sigma=3425)
53+
>>> float(gaussian(2523, mu=234234, sigma=3425))
5454
0.0
5555
"""
5656
return 1 / sqrt(2 * pi * sigma**2) * exp(-((x - mu) ** 2) / (2 * sigma**2))

‎maths/minkowski_distance.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def minkowski_distance(
1919
>>> minkowski_distance([1.0, 2.0, 3.0, 4.0], [5.0, 6.0, 7.0, 8.0], 2)
2020
8.0
2121
>>> import numpy as np
22-
>>> np.isclose(5.0, minkowski_distance([5.0], [0.0], 3))
22+
>>> bool(np.isclose(5.0, minkowski_distance([5.0], [0.0], 3)))
2323
True
2424
>>> minkowski_distance([1.0], [2.0], -1)
2525
Traceback (most recent call last):

‎maths/numerical_analysis/adams_bashforth.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def step_3(self) -> np.ndarray:
102102
>>> def f(x, y):
103103
... return x + y
104104
>>> y = AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_3()
105-
>>> y[3]
105+
>>> float(y[3])
106106
0.15533333333333332
107107
108108
>>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_3()
@@ -140,9 +140,9 @@ def step_4(self) -> np.ndarray:
140140
... return x + y
141141
>>> y = AdamsBashforth(
142142
... f, [0, 0.2, 0.4, 0.6], [0, 0, 0.04, 0.128], 0.2, 1).step_4()
143-
>>> y[4]
143+
>>> float(y[4])
144144
0.30699999999999994
145-
>>> y[5]
145+
>>> float(y[5])
146146
0.5771083333333333
147147
148148
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_4()
@@ -185,7 +185,7 @@ def step_5(self) -> np.ndarray:
185185
>>> y = AdamsBashforth(
186186
... f, [0, 0.2, 0.4, 0.6, 0.8], [0, 0.02140, 0.02140, 0.22211, 0.42536],
187187
... 0.2, 1).step_5()
188-
>>> y[-1]
188+
>>> float(y[-1])
189189
0.05436839444444452
190190
191191
>>> AdamsBashforth(f, [0, 0.2, 0.4], [0, 0, 0.04], 0.2, 1).step_5()

‎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))

‎maths/numerical_analysis/runge_kutta_fehlberg_45.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ def runge_kutta_fehlberg_45(
3434
>>> def f(x, y):
3535
... return 1 + y**2
3636
>>> y = runge_kutta_fehlberg_45(f, 0, 0, 0.2, 1)
37-
>>> y[1]
37+
>>> float(y[1])
3838
0.2027100937470787
3939
>>> def f(x,y):
4040
... return x
4141
>>> y = runge_kutta_fehlberg_45(f, -1, 0, 0.2, 0)
42-
>>> y[1]
42+
>>> float(y[1])
4343
-0.18000000000000002
4444
>>> y = runge_kutta_fehlberg_45(5, 0, 0, 0.1, 1)
4545
Traceback (most recent call last):

‎maths/numerical_analysis/runge_kutta_gills.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def runge_kutta_gills(
3434
>>> def f(x, y):
3535
... return (x-y)/2
3636
>>> y = runge_kutta_gills(f, 0, 3, 0.2, 5)
37-
>>> y[-1]
37+
>>> float(y[-1])
3838
3.4104259225717537
3939
4040
>>> def f(x,y):

‎maths/softmax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def softmax(vector):
2828
2929
The softmax vector adds up to one. We need to ceil to mitigate for
3030
precision
31-
>>> np.ceil(np.sum(softmax([1,2,3,4])))
31+
>>> float(np.ceil(np.sum(softmax([1,2,3,4]))))
3232
1.0
3333
3434
>>> vec = np.array([5,5])

‎neural_network/two_hidden_layers_neural_network.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def feedforward(self) -> np.ndarray:
6464
>>> nn = TwoHiddenLayerNeuralNetwork(input_val, output_val)
6565
>>> res = nn.feedforward()
6666
>>> array_sum = np.sum(res)
67-
>>> np.isnan(array_sum)
67+
>>> bool(np.isnan(array_sum))
6868
False
6969
"""
7070
# Layer_between_input_and_first_hidden_layer is the layer connecting the
@@ -105,7 +105,7 @@ def back_propagation(self) -> None:
105105
>>> res = nn.feedforward()
106106
>>> nn.back_propagation()
107107
>>> updated_weights = nn.second_hidden_layer_and_output_layer_weights
108-
>>> (res == updated_weights).all()
108+
>>> bool((res == updated_weights).all())
109109
False
110110
"""
111111

@@ -171,7 +171,7 @@ def train(self, output: np.ndarray, iterations: int, give_loss: bool) -> None:
171171
>>> first_iteration_weights = nn.feedforward()
172172
>>> nn.back_propagation()
173173
>>> updated_weights = nn.second_hidden_layer_and_output_layer_weights
174-
>>> (first_iteration_weights == updated_weights).all()
174+
>>> bool((first_iteration_weights == updated_weights).all())
175175
False
176176
"""
177177
for iteration in range(1, iterations + 1):

‎other/bankers_algorithm.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,11 @@ def __need_index_manager(self) -> dict[int, list[int]]:
8787
This function builds an index control dictionary to track original ids/indices
8888
of processes when altered during execution of method "main"
8989
Return: {0: [a: int, b: int], 1: [c: int, d: int]}
90-
>>> (BankersAlgorithm(test_claim_vector, test_allocated_res_table,
91-
... test_maximum_claim_table)._BankersAlgorithm__need_index_manager()
92-
... ) # doctest: +NORMALIZE_WHITESPACE
90+
>>> index_control = BankersAlgorithm(
91+
... test_claim_vector, test_allocated_res_table, test_maximum_claim_table
92+
... )._BankersAlgorithm__need_index_manager()
93+
>>> {key: [int(x) for x in value] for key, value
94+
... in index_control.items()} # doctest: +NORMALIZE_WHITESPACE
9395
{0: [1, 2, 0, 3], 1: [0, 1, 3, 1], 2: [1, 1, 0, 2], 3: [1, 3, 2, 0],
9496
4: [2, 0, 0, 3]}
9597
"""

‎physics/in_static_equilibrium.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def in_static_equilibrium(
5353
# summation of moments is zero
5454
moments: NDArray[float64] = cross(location, forces)
5555
sum_moments: float = sum(moments)
56-
return abs(sum_moments) < eps
56+
return bool(abs(sum_moments) < eps)
5757

5858

5959
if __name__ == "__main__":

‎requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
beautifulsoup4
22
fake_useragent
33
imageio
4-
keras ; python_version < '3.12'
4+
keras
55
lxml
66
matplotlib
77
numpy
@@ -17,7 +17,7 @@ rich
1717
scikit-learn
1818
statsmodels
1919
sympy
20-
tensorflow
20+
tensorflow ; python_version < '3.13'
2121
tweepy
2222
# yulewalker # uncomment once audio_filters/equal_loudness_filter.py is fixed
2323
typing_extensions

0 commit comments

Comments
 (0)
Please sign in to comment.