PyPyNum 1.13.0__py3-none-any.whl → 1.13.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {PyPyNum-1.13.0.dist-info → PyPyNum-1.13.1.dist-info}/METADATA +39 -103
- {PyPyNum-1.13.0.dist-info → PyPyNum-1.13.1.dist-info}/RECORD +12 -12
- pypynum/Matrix.py +3 -3
- pypynum/README.md +38 -102
- pypynum/__init__.py +1 -1
- pypynum/errors.py +4 -0
- pypynum/interp.py +1 -1
- pypynum/multiprec.py +38 -4
- pypynum/test.py +0 -11
- pypynum/tools.py +33 -0
- {PyPyNum-1.13.0.dist-info → PyPyNum-1.13.1.dist-info}/WHEEL +0 -0
- {PyPyNum-1.13.0.dist-info → PyPyNum-1.13.1.dist-info}/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyPyNum
|
|
3
|
-
Version: 1.13.
|
|
3
|
+
Version: 1.13.1
|
|
4
4
|
Summary: PyPyNum is a Python library for math & science computations, covering algebra, calculus, stats, with data structures like matrices, vectors, tensors. It offers numerical tools, programs, and supports computational ops, functions, processing, simulation, & visualization in data science & ML, crucial for research, engineering, & data processing.
|
|
5
5
|
Home-page: https://github.com/PythonSJL/PyPyNum
|
|
6
6
|
Author: Shen Jiayi
|
|
@@ -234,7 +234,7 @@ processing.</font><font color = red>[Python>=3.4]</font>
|
|
|
234
234
|
[](https://pepy.tech/project/pypynum)
|
|
235
235
|
[](https://pepy.tech/project/pypynum)
|
|
236
236
|
|
|
237
|
-
## Version -> 1.13.
|
|
237
|
+
## Version -> 1.13.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
|
|
238
238
|
|
|
239
239
|

|
|
240
240
|
|
|
@@ -339,102 +339,48 @@ Python interpreter and run it!
|
|
|
339
339
|
```
|
|
340
340
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
341
341
|
|
|
342
|
-
|
|
342
|
+
修正了MPComplex的错误并且新增了部分用
|
|
343
|
+
于计算三角函数的方法
|
|
343
344
|
|
|
344
|
-
|
|
345
|
+
Corrected errors in MPComplex
|
|
346
|
+
and added some methods for
|
|
347
|
+
calculating trigonometric
|
|
348
|
+
functions
|
|
345
349
|
|
|
346
|
-
|
|
347
|
-
mp_acos(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
348
|
-
mp_asin(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
349
|
-
mp_fresnel_c(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
350
|
-
mp_fresnel_s(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
350
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
351
351
|
|
|
352
|
+
增加了levenshtein_distance函数
|
|
352
353
|
|
|
353
|
-
|
|
354
|
-
其实现了多精度复数计算,
|
|
355
|
-
目前支持加、减、乘、除、指数、对数等运算,
|
|
356
|
-
并且将在后面的版本增加各种三角函数。
|
|
354
|
+
Added levenshtein_distance function
|
|
357
355
|
|
|
358
|
-
The MPComplex class has been added,
|
|
359
|
-
which implements multi precision complex calculations.
|
|
360
|
-
Currently,
|
|
361
|
-
it supports operations such as addition,
|
|
362
|
-
subtraction,
|
|
363
|
-
multiplication,
|
|
364
|
-
division,
|
|
365
|
-
exponentiation,
|
|
366
|
-
and logarithm,
|
|
367
|
-
and various trigonometric functions will be added in later versions.
|
|
368
356
|
|
|
369
|
-
|
|
357
|
+
Help on function levenshtein_distance in module pypynum.tools:
|
|
370
358
|
|
|
359
|
+
levenshtein_distance(s1: str, s2: str) -> int
|
|
360
|
+
Introduction
|
|
361
|
+
==========
|
|
362
|
+
Calculate the Levenshtein distance between two strings.
|
|
371
363
|
|
|
372
|
-
|
|
373
|
-
|
|
364
|
+
The Levenshtein distance is a measure of the difference between two strings. It is defined as the minimum number
|
|
365
|
+
of single-character edits (i.e., insertions, deletions or substitutions) required to change one string into the
|
|
366
|
+
other.
|
|
374
367
|
|
|
375
|
-
|
|
376
|
-
|
|
368
|
+
Example
|
|
369
|
+
==========
|
|
370
|
+
>>> levenshtein_distance("kitten", "sitting")
|
|
371
|
+
3
|
|
372
|
+
>>>
|
|
373
|
+
:param s1: First string to compare.
|
|
374
|
+
:param s2: Second string to compare.
|
|
375
|
+
:return: The Levenshtein distance between the two strings.
|
|
377
376
|
|
|
378
377
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
379
378
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
Help on module pypynum.interp in pypynum:
|
|
388
|
-
|
|
389
|
-
NAME
|
|
390
|
-
pypynum.interp
|
|
391
|
-
|
|
392
|
-
FUNCTIONS
|
|
393
|
-
bicubic(x)
|
|
394
|
-
Calculate the cubic B-spline interpolation function value.
|
|
395
|
-
:param x: The x value for which the B-spline function is evaluated.
|
|
396
|
-
:return: The value of the cubic B-spline function at x.
|
|
397
|
-
|
|
398
|
-
contribute(src, x, y, channels=None)
|
|
399
|
-
Calculate the contribution of the source array at a specific point after bicubic interpolation.
|
|
400
|
-
:param src: The source 2D array from which to interpolate.
|
|
401
|
-
:param x: The x-coordinate of the point to interpolate.
|
|
402
|
-
:param y: The y-coordinate of the point to interpolate.
|
|
403
|
-
:param channels: The number of channels if src is a multichannel array.
|
|
404
|
-
:return: The interpolated value at the point (x, y).
|
|
405
|
-
|
|
406
|
-
interp1d(data: Union[list, tuple], length: int) -> list
|
|
407
|
-
Introduction
|
|
408
|
-
==========
|
|
409
|
-
One-dimensional data interpolation
|
|
410
|
-
|
|
411
|
-
Example
|
|
412
|
-
==========
|
|
413
|
-
>>> interp1d((2, 4, 4, 2), 6)
|
|
414
|
-
[2, 3.320000000000001, 4.160000000000005, 4.160000000000012, 3.3200000000000074, 2]
|
|
415
|
-
>>>
|
|
416
|
-
:param data: List of data points to be interpolated. Must be at least two points.
|
|
417
|
-
:param length: The number of points in the resampled data set.
|
|
418
|
-
:return: A list of interpolated values at the new points.
|
|
419
|
-
|
|
420
|
-
interp2d(src, new_height, new_width, channels=None, round_res=False, min_val=None, max_val=None)
|
|
421
|
-
Introduction
|
|
422
|
-
==========
|
|
423
|
-
Two-dimensional data interpolation using bicubic spline interpolation.
|
|
424
|
-
|
|
425
|
-
Example
|
|
426
|
-
==========
|
|
427
|
-
>>> interp2d([[1, 2], [3, 4]], 3, 3)
|
|
428
|
-
[[1.0, 1.6875, 2.0], [2.25, 3.1640625, 3.375], [3.0, 3.9375, 4.0]]
|
|
429
|
-
>>>
|
|
430
|
-
:param src: The source 2D array to be interpolated.
|
|
431
|
-
:param new_height: The desired height of the interpolated array.
|
|
432
|
-
:param new_width: The desired width of the interpolated array.
|
|
433
|
-
:param channels: The number of channels if src is a multichannel array.
|
|
434
|
-
:param round_res: Whether to round the result to the nearest integer.
|
|
435
|
-
:param min_val: The minimum value to clip the interpolated results.
|
|
436
|
-
:param max_val: The maximum value to clip the interpolated results.
|
|
437
|
-
:return: A 2D array of the interpolated values with the new dimensions.
|
|
379
|
+
注意:以后的版本中的自述文件将更改为纯英文
|
|
380
|
+
|
|
381
|
+
Attention: The self description
|
|
382
|
+
file in future versions will be
|
|
383
|
+
changed to pure English
|
|
438
384
|
|
|
439
385
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
440
386
|
```
|
|
@@ -876,6 +822,7 @@ PyPyNum
|
|
|
876
822
|
│ ├── generate_primes(limit: int) -> list
|
|
877
823
|
│ ├── generate_semiprimes(limit: int) -> list
|
|
878
824
|
│ ├── geomspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
825
|
+
│ ├── levenshtein_distance(s1: str, s2: str) -> int
|
|
879
826
|
│ ├── linspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
880
827
|
│ ├── magic_square(n: Any) -> Any
|
|
881
828
|
│ ├── primality(n: int, iter_num: int) -> bool
|
|
@@ -1256,8 +1203,8 @@ print(equations.poly_eq(p))
|
|
|
1256
1203
|
print(equations.lin_eq(*m))
|
|
1257
1204
|
|
|
1258
1205
|
"""
|
|
1259
|
-
[(-1.5615528128088307-6.5209667308287455e-24j)
|
|
1260
|
-
[
|
|
1206
|
+
[(-1.5615528128088307-6.5209667308287455e-24j), (1.0000000000000007+3.241554513744382e-25j), (2.5615528128088294+4.456233626665941e-24j)]
|
|
1207
|
+
[1.6666666666666665, -0.6666666666666666, -0.4444444444444444]
|
|
1261
1208
|
"""
|
|
1262
1209
|
|
|
1263
1210
|
print(maths.cot(constants.pi / 3))
|
|
@@ -1357,10 +1304,10 @@ print(random.randint(0, 9, [2, 3, 4]))
|
|
|
1357
1304
|
print(random.uniform(0, 9, [2, 3, 4]))
|
|
1358
1305
|
|
|
1359
1306
|
"""
|
|
1360
|
-
[[[
|
|
1361
|
-
[[[0.
|
|
1362
|
-
[[[
|
|
1363
|
-
[[[
|
|
1307
|
+
[[[0.015128082827448793, -0.731558889632968, -0.23379102528494308, 0.5923285646572862], [0.6389462900078073, -1.6347914510943111, 2.3694029836271726, -0.568526047386569], [-1.4229328154353735, 0.45185125607678145, -0.4003256267251042, -1.1425679894907612]], [[1.2876668616276734, 0.934232416262927, -1.4096609242818299, 0.2683613962988281], [0.3503627719719857, 1.9613965063102903, -2.0790609695353077, -0.10339725500993839], [-0.9334087233797456, 1.1394611182611, 1.3341558691128073, -0.3838574172857678]]]
|
|
1308
|
+
[[[0.8274205130045614, 0.27524584776494854, 0.715710895889572, 0.5807271906102146], [0.21742840470887725, 0.04577819370109826, 0.873689463957162, 0.04119770233167375], [0.554823367037196, 0.5901404246422433, 0.21342393541488192, 0.2979716283166385]], [[0.6045948602408673, 0.265586003384665, 0.9646655285283718, 0.9873208424367568], [0.16916505841642293, 0.15942804932580645, 0.679004396069304, 0.4586819952716237], [0.6058239213086706, 0.37021967026096103, 0.0015603885735545608, 0.8432925281217005]]]
|
|
1309
|
+
[[[7, 2, 9, 7], [0, 5, 1, 3], [9, 1, 0, 2]], [[1, 2, 7, 5], [5, 7, 4, 1], [2, 5, 7, 9]]]
|
|
1310
|
+
[[[1.6682230173222767, 0.5174279535822173, 6.202024157209834, 5.097176032335483], [3.44538825088208, 3.7119354081208025, 4.584800897579607, 8.294514147889751], [7.201908571787272, 4.96544760729807, 5.896259095293225, 3.215472062129558]], [[6.352678024277219, 6.894646335413341, 2.0445980257056333, 1.5835361381716893], [6.363077167625872, 8.831103031792672, 6.229821243776864, 0.5639371628314593], [7.639545178199688, 8.079077083978365, 8.063058392021144, 8.673394953496695]]]
|
|
1364
1311
|
"""
|
|
1365
1312
|
|
|
1366
1313
|
print(regression.lin_reg(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -1385,19 +1332,8 @@ print(tools.linspace(0, 2.8, 8))
|
|
|
1385
1332
|
[0.0, 0.39999999999999997, 0.7999999999999999, 1.2, 1.5999999999999999, 1.9999999999999998, 2.4, 2.8]
|
|
1386
1333
|
"""
|
|
1387
1334
|
|
|
1388
|
-
# 提示:
|
|
1389
|
-
#
|
|
1390
|
-
# 测试已成功通过并结束。
|
|
1391
|
-
#
|
|
1392
|
-
# 这些测试只是这个包功能的一部分。
|
|
1393
|
-
#
|
|
1394
|
-
# 更多的功能需要自己探索和尝试!
|
|
1395
|
-
#
|
|
1396
1335
|
# Tip:
|
|
1397
|
-
#
|
|
1398
1336
|
# The test has been successfully passed and ended.
|
|
1399
|
-
#
|
|
1400
1337
|
# These tests are only part of the functionality of this package.
|
|
1401
|
-
#
|
|
1402
1338
|
# More features need to be explored and tried by yourself!
|
|
1403
1339
|
```
|
|
@@ -4,28 +4,28 @@ pypynum/Geometry.py,sha256=bJCuif-wHO-t7oHFEE7ntzIdQwzUEbT3mcKgmBV6Wps,13982
|
|
|
4
4
|
pypynum/Graph.py,sha256=m9iTCNYRCZmAexDzwJ8Y6J7v1aweT-6TZkqh4fOtZDE,10131
|
|
5
5
|
pypynum/Group.py,sha256=kzUR_r10ubOB2o51rKKdQPHRsgdTGL2yoY7yseKInZc,4263
|
|
6
6
|
pypynum/Logic.py,sha256=IJAv59ECHU0HmG9lYCAQ_puqeL6Zor3-IDIVH48KBWE,11000
|
|
7
|
-
pypynum/Matrix.py,sha256=
|
|
7
|
+
pypynum/Matrix.py,sha256=_MMb2HsarLzPRGIR2tI4G7yPPvYpjIODYMgf6wdQmxw,20344
|
|
8
8
|
pypynum/NeuralN.py,sha256=iSOvC9JW1h4AFGokGGOTkKie5hAYN_YT9H4f3apI9b8,3275
|
|
9
9
|
pypynum/PyPyNum.png,sha256=t96tJPWfHxT8kcXm_qZI2z5W36TgOqjCU9qdgbmlFws,11623
|
|
10
10
|
pypynum/Quaternion.py,sha256=-BW_crP_i-veHN0_pD3Z1dipFNUX198oZDrUYTsoZw0,8017
|
|
11
|
-
pypynum/README.md,sha256=
|
|
11
|
+
pypynum/README.md,sha256=6WXIDNu_Tc5fHBpNIbzDCV8PWszDFCivzKenPuYc660,74771
|
|
12
12
|
pypynum/Symbolics.py,sha256=u-Dig3OLs6qoLzxMpTAYJGq5uSWDMvgU13TAHKLyjMY,2768
|
|
13
13
|
pypynum/Tensor.py,sha256=gi7OjrGgP5BSJS9Oma1B2EdX9qSpMNIP2BnKLojdT78,3930
|
|
14
14
|
pypynum/Tree.py,sha256=BYnlb2kKNJ8kkuq8BAHIcLvPZw5KHxbvM7YuVGhQVMk,4330
|
|
15
15
|
pypynum/Vector.py,sha256=ee-gkBtyG0l5dLFwAKRTTlnDG05pWpM19RGN7VoPvqE,3212
|
|
16
|
-
pypynum/__init__.py,sha256=
|
|
16
|
+
pypynum/__init__.py,sha256=TqL88yyyOIW5Jp54b4ZqS1jr3J9bwo9VWLBDkh8ied8,2896
|
|
17
17
|
pypynum/chars.py,sha256=ZOXZn2VzxmpHuvZ87ojhEib3CfTNgysRsFMFITHOA2E,2179
|
|
18
18
|
pypynum/cipher.py,sha256=DaitY3DCoTuzyrXtD8Ap3IYDLhlMc7-o4AJfLlicvB4,10011
|
|
19
19
|
pypynum/confs.py,sha256=iFz83iZ1A4BK4LTqo-ZbpAcoxhYWUxtEQKsr_-d8ryw,2869
|
|
20
20
|
pypynum/constants.py,sha256=xELv4DIKEqBdwF9tUqCmTQVbgVrlrj385ht5eawvshU,1406
|
|
21
21
|
pypynum/dists.py,sha256=WHDeM0oC4Do77p9TVVMu3pgWzI04gYdK_s1TNGhets0,29697
|
|
22
22
|
pypynum/equations.py,sha256=26XEQBIcL3cyPLO6YFvBK1dlFHw-du3nQG4-cXAFYe0,557
|
|
23
|
-
pypynum/errors.py,sha256=
|
|
23
|
+
pypynum/errors.py,sha256=XlK5yazNbNtnbM4toT_bdI41u-q-AUkZsa7dqc5dQb0,264
|
|
24
24
|
pypynum/file.py,sha256=-sg3pndZdiyM8cS6KeIhCvB6NfAovHnLOhEf0XkjidE,3411
|
|
25
25
|
pypynum/image.py,sha256=nhTZmaBVIKhuar-CcwZWb-hRYmkj4b_g7vIlYvEJEEE,12155
|
|
26
|
-
pypynum/interp.py,sha256=
|
|
26
|
+
pypynum/interp.py,sha256=X1LN4WiVYkZlyKXvK_KJ2KDgjDiW_-tqgFM4ySQ3yJk,4897
|
|
27
27
|
pypynum/maths.py,sha256=cERFo7YK191xZ3JnshzXk4am9maTJUIeIEf1zIQitIM,31764
|
|
28
|
-
pypynum/multiprec.py,sha256=
|
|
28
|
+
pypynum/multiprec.py,sha256=W4G48VXsTs13VFolcTjcE_BHQWccdl2PlC5coAT4V90,18405
|
|
29
29
|
pypynum/numbers.py,sha256=PqQ07TWfcNlfjCjUg1UJda-BI1uOffmQVK1qIGbll_s,8619
|
|
30
30
|
pypynum/plotting.py,sha256=mbIYK5TpY1qvuMJrqz4d8bxJEiZww3AI684vSKV-DgU,7781
|
|
31
31
|
pypynum/polynomial.py,sha256=60hDQG_iRwduFFqawSTzAG6F3eHqfgrSnSGDwBLQB-s,14587
|
|
@@ -34,14 +34,14 @@ pypynum/random.py,sha256=qy2ISoHQVJ-zOVITplmCGvWEw-EZc18r-hZl8dvDimE,2274
|
|
|
34
34
|
pypynum/regression.py,sha256=PfTM8glJSi3Jgvc_C_3hQBeVjkbrzSuDqRbEf3s403w,2040
|
|
35
35
|
pypynum/sequence.py,sha256=7NSZm_p_B00KFj5XZrtSm2FXhsowxs0qg_Q_P4pAA8o,7194
|
|
36
36
|
pypynum/stattest.py,sha256=W1041KeVsvdcLKFJOK4hQm_DjO5ZjUE8WEmGUe-4_Zk,5507
|
|
37
|
-
pypynum/test.py,sha256=
|
|
37
|
+
pypynum/test.py,sha256=tjJI8YkAqNEtwNeFsixWliZfc3J1qVpgCo4u-Wh9kvw,8826
|
|
38
38
|
pypynum/this.py,sha256=oRX1OpMa4NJmQSdEjJxfszEo5FRYlxRiF8OTDRIcdMA,2154
|
|
39
|
-
pypynum/tools.py,sha256=
|
|
39
|
+
pypynum/tools.py,sha256=0k8ZC-LcZ9BZqPYV487aPr95K1EoX-oHOalWjg9or3Y,12554
|
|
40
40
|
pypynum/types.py,sha256=ek9tydfCspsjcvxVFv_rJegnTHl6PHwKPdqjvHfkvDg,246
|
|
41
41
|
pypynum/ufuncs.py,sha256=g2tewdsGa4VrIq2khR-0SWJoXBitVRN87DulOnTxxDA,2572
|
|
42
42
|
pypynum/utils.py,sha256=OqUFVraYDTSubF9QhZm8WC6A0ppnkhVU0YtAeYN9EyU,21048
|
|
43
43
|
pypynum/zh_cn.py,sha256=Ky9AWuW64Vbhg_Pdn0Yksls7IEM_zk7uz1bb4iKmGNc,13008
|
|
44
|
-
PyPyNum-1.13.
|
|
45
|
-
PyPyNum-1.13.
|
|
46
|
-
PyPyNum-1.13.
|
|
47
|
-
PyPyNum-1.13.
|
|
44
|
+
PyPyNum-1.13.1.dist-info/METADATA,sha256=obf7t8Nu3EQH3DUm9tWPCgJYuvzNQVtlagsQpvCsS1c,89150
|
|
45
|
+
PyPyNum-1.13.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
46
|
+
PyPyNum-1.13.1.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
|
|
47
|
+
PyPyNum-1.13.1.dist-info/RECORD,,
|
pypynum/Matrix.py
CHANGED
|
@@ -356,7 +356,7 @@ def hessenberg(matrix: Matrix) -> tuple:
|
|
|
356
356
|
continue
|
|
357
357
|
h = 0.0
|
|
358
358
|
for k in range(0, i):
|
|
359
|
-
a[i, k]
|
|
359
|
+
a[i, k] *= scale_inv
|
|
360
360
|
rr, ii = a[i, k].real, a[i, k].imag
|
|
361
361
|
h += rr * rr + ii * ii
|
|
362
362
|
f = a[i, i - 1]
|
|
@@ -373,7 +373,7 @@ def hessenberg(matrix: Matrix) -> tuple:
|
|
|
373
373
|
h = 1 / sqrt(h)
|
|
374
374
|
t[i] *= h
|
|
375
375
|
for k in range(0, i - 1):
|
|
376
|
-
a[i, k]
|
|
376
|
+
a[i, k] *= h
|
|
377
377
|
for j in range(0, i):
|
|
378
378
|
g = t[i].conjugate() * a[j, i - 1]
|
|
379
379
|
for k in range(0, i - 1):
|
|
@@ -547,7 +547,7 @@ def eigen(matrix: Matrix) -> tuple:
|
|
|
547
547
|
|
|
548
548
|
|
|
549
549
|
def svd(matrix: Matrix) -> tuple:
|
|
550
|
-
print("\
|
|
550
|
+
print("\nWarning: The SVD function may have calculation errors\n")
|
|
551
551
|
e0, u = eigen(matrix @ matrix.t())
|
|
552
552
|
u = Matrix([_[::-1] for _ in u])
|
|
553
553
|
e1, v = eigen(matrix.t() @ matrix)
|
pypynum/README.md
CHANGED
|
@@ -20,7 +20,7 @@ processing.</font><font color = red>[Python>=3.4]</font>
|
|
|
20
20
|
[](https://pepy.tech/project/pypynum)
|
|
21
21
|
[](https://pepy.tech/project/pypynum)
|
|
22
22
|
|
|
23
|
-
## Version -> 1.13.
|
|
23
|
+
## Version -> 1.13.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
|
|
24
24
|
|
|
25
25
|

|
|
26
26
|
|
|
@@ -125,102 +125,48 @@ Python interpreter and run it!
|
|
|
125
125
|
```
|
|
126
126
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
修正了MPComplex的错误并且新增了部分用
|
|
129
|
+
于计算三角函数的方法
|
|
129
130
|
|
|
130
|
-
|
|
131
|
+
Corrected errors in MPComplex
|
|
132
|
+
and added some methods for
|
|
133
|
+
calculating trigonometric
|
|
134
|
+
functions
|
|
131
135
|
|
|
132
|
-
|
|
133
|
-
mp_acos(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
134
|
-
mp_asin(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
135
|
-
mp_fresnel_c(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
136
|
-
mp_fresnel_s(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
|
|
136
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
137
137
|
|
|
138
|
+
增加了levenshtein_distance函数
|
|
138
139
|
|
|
139
|
-
|
|
140
|
-
其实现了多精度复数计算,
|
|
141
|
-
目前支持加、减、乘、除、指数、对数等运算,
|
|
142
|
-
并且将在后面的版本增加各种三角函数。
|
|
140
|
+
Added levenshtein_distance function
|
|
143
141
|
|
|
144
|
-
The MPComplex class has been added,
|
|
145
|
-
which implements multi precision complex calculations.
|
|
146
|
-
Currently,
|
|
147
|
-
it supports operations such as addition,
|
|
148
|
-
subtraction,
|
|
149
|
-
multiplication,
|
|
150
|
-
division,
|
|
151
|
-
exponentiation,
|
|
152
|
-
and logarithm,
|
|
153
|
-
and various trigonometric functions will be added in later versions.
|
|
154
142
|
|
|
155
|
-
|
|
143
|
+
Help on function levenshtein_distance in module pypynum.tools:
|
|
156
144
|
|
|
145
|
+
levenshtein_distance(s1: str, s2: str) -> int
|
|
146
|
+
Introduction
|
|
147
|
+
==========
|
|
148
|
+
Calculate the Levenshtein distance between two strings.
|
|
157
149
|
|
|
158
|
-
|
|
159
|
-
|
|
150
|
+
The Levenshtein distance is a measure of the difference between two strings. It is defined as the minimum number
|
|
151
|
+
of single-character edits (i.e., insertions, deletions or substitutions) required to change one string into the
|
|
152
|
+
other.
|
|
160
153
|
|
|
161
|
-
|
|
162
|
-
|
|
154
|
+
Example
|
|
155
|
+
==========
|
|
156
|
+
>>> levenshtein_distance("kitten", "sitting")
|
|
157
|
+
3
|
|
158
|
+
>>>
|
|
159
|
+
:param s1: First string to compare.
|
|
160
|
+
:param s2: Second string to compare.
|
|
161
|
+
:return: The Levenshtein distance between the two strings.
|
|
163
162
|
|
|
164
163
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
165
164
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
Help on module pypynum.interp in pypynum:
|
|
174
|
-
|
|
175
|
-
NAME
|
|
176
|
-
pypynum.interp
|
|
177
|
-
|
|
178
|
-
FUNCTIONS
|
|
179
|
-
bicubic(x)
|
|
180
|
-
Calculate the cubic B-spline interpolation function value.
|
|
181
|
-
:param x: The x value for which the B-spline function is evaluated.
|
|
182
|
-
:return: The value of the cubic B-spline function at x.
|
|
183
|
-
|
|
184
|
-
contribute(src, x, y, channels=None)
|
|
185
|
-
Calculate the contribution of the source array at a specific point after bicubic interpolation.
|
|
186
|
-
:param src: The source 2D array from which to interpolate.
|
|
187
|
-
:param x: The x-coordinate of the point to interpolate.
|
|
188
|
-
:param y: The y-coordinate of the point to interpolate.
|
|
189
|
-
:param channels: The number of channels if src is a multichannel array.
|
|
190
|
-
:return: The interpolated value at the point (x, y).
|
|
191
|
-
|
|
192
|
-
interp1d(data: Union[list, tuple], length: int) -> list
|
|
193
|
-
Introduction
|
|
194
|
-
==========
|
|
195
|
-
One-dimensional data interpolation
|
|
196
|
-
|
|
197
|
-
Example
|
|
198
|
-
==========
|
|
199
|
-
>>> interp1d((2, 4, 4, 2), 6)
|
|
200
|
-
[2, 3.320000000000001, 4.160000000000005, 4.160000000000012, 3.3200000000000074, 2]
|
|
201
|
-
>>>
|
|
202
|
-
:param data: List of data points to be interpolated. Must be at least two points.
|
|
203
|
-
:param length: The number of points in the resampled data set.
|
|
204
|
-
:return: A list of interpolated values at the new points.
|
|
205
|
-
|
|
206
|
-
interp2d(src, new_height, new_width, channels=None, round_res=False, min_val=None, max_val=None)
|
|
207
|
-
Introduction
|
|
208
|
-
==========
|
|
209
|
-
Two-dimensional data interpolation using bicubic spline interpolation.
|
|
210
|
-
|
|
211
|
-
Example
|
|
212
|
-
==========
|
|
213
|
-
>>> interp2d([[1, 2], [3, 4]], 3, 3)
|
|
214
|
-
[[1.0, 1.6875, 2.0], [2.25, 3.1640625, 3.375], [3.0, 3.9375, 4.0]]
|
|
215
|
-
>>>
|
|
216
|
-
:param src: The source 2D array to be interpolated.
|
|
217
|
-
:param new_height: The desired height of the interpolated array.
|
|
218
|
-
:param new_width: The desired width of the interpolated array.
|
|
219
|
-
:param channels: The number of channels if src is a multichannel array.
|
|
220
|
-
:param round_res: Whether to round the result to the nearest integer.
|
|
221
|
-
:param min_val: The minimum value to clip the interpolated results.
|
|
222
|
-
:param max_val: The maximum value to clip the interpolated results.
|
|
223
|
-
:return: A 2D array of the interpolated values with the new dimensions.
|
|
165
|
+
注意:以后的版本中的自述文件将更改为纯英文
|
|
166
|
+
|
|
167
|
+
Attention: The self description
|
|
168
|
+
file in future versions will be
|
|
169
|
+
changed to pure English
|
|
224
170
|
|
|
225
171
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
226
172
|
```
|
|
@@ -662,6 +608,7 @@ PyPyNum
|
|
|
662
608
|
│ ├── generate_primes(limit: int) -> list
|
|
663
609
|
│ ├── generate_semiprimes(limit: int) -> list
|
|
664
610
|
│ ├── geomspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
611
|
+
│ ├── levenshtein_distance(s1: str, s2: str) -> int
|
|
665
612
|
│ ├── linspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
|
|
666
613
|
│ ├── magic_square(n: Any) -> Any
|
|
667
614
|
│ ├── primality(n: int, iter_num: int) -> bool
|
|
@@ -1042,8 +989,8 @@ print(equations.poly_eq(p))
|
|
|
1042
989
|
print(equations.lin_eq(*m))
|
|
1043
990
|
|
|
1044
991
|
"""
|
|
1045
|
-
[(-1.5615528128088307-6.5209667308287455e-24j)
|
|
1046
|
-
[
|
|
992
|
+
[(-1.5615528128088307-6.5209667308287455e-24j), (1.0000000000000007+3.241554513744382e-25j), (2.5615528128088294+4.456233626665941e-24j)]
|
|
993
|
+
[1.6666666666666665, -0.6666666666666666, -0.4444444444444444]
|
|
1047
994
|
"""
|
|
1048
995
|
|
|
1049
996
|
print(maths.cot(constants.pi / 3))
|
|
@@ -1143,10 +1090,10 @@ print(random.randint(0, 9, [2, 3, 4]))
|
|
|
1143
1090
|
print(random.uniform(0, 9, [2, 3, 4]))
|
|
1144
1091
|
|
|
1145
1092
|
"""
|
|
1146
|
-
[[[
|
|
1147
|
-
[[[0.
|
|
1148
|
-
[[[
|
|
1149
|
-
[[[
|
|
1093
|
+
[[[0.015128082827448793, -0.731558889632968, -0.23379102528494308, 0.5923285646572862], [0.6389462900078073, -1.6347914510943111, 2.3694029836271726, -0.568526047386569], [-1.4229328154353735, 0.45185125607678145, -0.4003256267251042, -1.1425679894907612]], [[1.2876668616276734, 0.934232416262927, -1.4096609242818299, 0.2683613962988281], [0.3503627719719857, 1.9613965063102903, -2.0790609695353077, -0.10339725500993839], [-0.9334087233797456, 1.1394611182611, 1.3341558691128073, -0.3838574172857678]]]
|
|
1094
|
+
[[[0.8274205130045614, 0.27524584776494854, 0.715710895889572, 0.5807271906102146], [0.21742840470887725, 0.04577819370109826, 0.873689463957162, 0.04119770233167375], [0.554823367037196, 0.5901404246422433, 0.21342393541488192, 0.2979716283166385]], [[0.6045948602408673, 0.265586003384665, 0.9646655285283718, 0.9873208424367568], [0.16916505841642293, 0.15942804932580645, 0.679004396069304, 0.4586819952716237], [0.6058239213086706, 0.37021967026096103, 0.0015603885735545608, 0.8432925281217005]]]
|
|
1095
|
+
[[[7, 2, 9, 7], [0, 5, 1, 3], [9, 1, 0, 2]], [[1, 2, 7, 5], [5, 7, 4, 1], [2, 5, 7, 9]]]
|
|
1096
|
+
[[[1.6682230173222767, 0.5174279535822173, 6.202024157209834, 5.097176032335483], [3.44538825088208, 3.7119354081208025, 4.584800897579607, 8.294514147889751], [7.201908571787272, 4.96544760729807, 5.896259095293225, 3.215472062129558]], [[6.352678024277219, 6.894646335413341, 2.0445980257056333, 1.5835361381716893], [6.363077167625872, 8.831103031792672, 6.229821243776864, 0.5639371628314593], [7.639545178199688, 8.079077083978365, 8.063058392021144, 8.673394953496695]]]
|
|
1150
1097
|
"""
|
|
1151
1098
|
|
|
1152
1099
|
print(regression.lin_reg(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -1171,19 +1118,8 @@ print(tools.linspace(0, 2.8, 8))
|
|
|
1171
1118
|
[0.0, 0.39999999999999997, 0.7999999999999999, 1.2, 1.5999999999999999, 1.9999999999999998, 2.4, 2.8]
|
|
1172
1119
|
"""
|
|
1173
1120
|
|
|
1174
|
-
# 提示:
|
|
1175
|
-
#
|
|
1176
|
-
# 测试已成功通过并结束。
|
|
1177
|
-
#
|
|
1178
|
-
# 这些测试只是这个包功能的一部分。
|
|
1179
|
-
#
|
|
1180
|
-
# 更多的功能需要自己探索和尝试!
|
|
1181
|
-
#
|
|
1182
1121
|
# Tip:
|
|
1183
|
-
#
|
|
1184
1122
|
# The test has been successfully passed and ended.
|
|
1185
|
-
#
|
|
1186
1123
|
# These tests are only part of the functionality of this package.
|
|
1187
|
-
#
|
|
1188
1124
|
# More features need to be explored and tried by yourself!
|
|
1189
1125
|
```
|
pypynum/__init__.py
CHANGED
|
@@ -66,7 +66,7 @@ from .utils import OrderedSet, InfIterator, LinkedList, IntervalSet
|
|
|
66
66
|
from .Vector import vec
|
|
67
67
|
from . import zh_cn
|
|
68
68
|
|
|
69
|
-
__version__ = "1.13.
|
|
69
|
+
__version__ = "1.13.1"
|
|
70
70
|
print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
|
|
71
71
|
"Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", "GitHub -> https://github.com/PythonSJL/PyPyNum", sep=" | ")
|
|
72
72
|
del math, arr, ite, num, prec, real, geom, ContentError, RandomError, LogicError, InputError, FullError, Union
|
pypynum/errors.py
CHANGED
pypynum/interp.py
CHANGED
pypynum/multiprec.py
CHANGED
|
@@ -399,21 +399,21 @@ class MPComplex:
|
|
|
399
399
|
self.sigfigs = sigfigs
|
|
400
400
|
|
|
401
401
|
def __add__(self, other):
|
|
402
|
-
other = asmpc(other, self.sigfigs)
|
|
402
|
+
other = asmpc(other, sigfigs=self.sigfigs)
|
|
403
403
|
return MPComplex(self.real + other.real, self.imag + other.imag, self.sigfigs)
|
|
404
404
|
|
|
405
405
|
def __sub__(self, other):
|
|
406
|
-
other = asmpc(other, self.sigfigs)
|
|
406
|
+
other = asmpc(other, sigfigs=self.sigfigs)
|
|
407
407
|
return MPComplex(self.real - other.real, self.imag - other.imag, self.sigfigs)
|
|
408
408
|
|
|
409
409
|
def __mul__(self, other):
|
|
410
|
-
other = asmpc(other, self.sigfigs)
|
|
410
|
+
other = asmpc(other, sigfigs=self.sigfigs)
|
|
411
411
|
real = self.real * other.real - self.imag * other.imag
|
|
412
412
|
imag = self.real * other.imag + self.imag * other.real
|
|
413
413
|
return MPComplex(real, imag, self.sigfigs)
|
|
414
414
|
|
|
415
415
|
def __truediv__(self, other):
|
|
416
|
-
other = asmpc(other, self.sigfigs)
|
|
416
|
+
other = asmpc(other, sigfigs=self.sigfigs)
|
|
417
417
|
if other.real == 0 and other.imag == 0:
|
|
418
418
|
raise ZeroDivisionError("Cannot divide by zero")
|
|
419
419
|
else:
|
|
@@ -513,6 +513,40 @@ class MPComplex:
|
|
|
513
513
|
def __repr__(self):
|
|
514
514
|
return "MPComplex({!r}, {!r}, sigfigs={!r})".format(self.real, self.imag, self.sigfigs)
|
|
515
515
|
|
|
516
|
+
def sin(self):
|
|
517
|
+
real_part = mp_sin(self.real, self.sigfigs + 5) * mp_cosh(self.imag, self.sigfigs + 5)
|
|
518
|
+
imag_part = mp_cos(self.real, self.sigfigs + 5) * mp_sinh(self.imag, self.sigfigs + 5)
|
|
519
|
+
return MPComplex(real_part, imag_part, self.sigfigs)
|
|
520
|
+
|
|
521
|
+
def cos(self):
|
|
522
|
+
real_part = mp_cos(self.real, self.sigfigs + 5) * mp_cosh(self.imag, self.sigfigs + 5)
|
|
523
|
+
imag_part = -mp_sin(self.real, self.sigfigs + 5) * mp_sinh(self.imag, self.sigfigs + 5)
|
|
524
|
+
return MPComplex(real_part, imag_part, self.sigfigs)
|
|
525
|
+
|
|
526
|
+
def tan(self):
|
|
527
|
+
cos_z = self.cos()
|
|
528
|
+
if cos_z.real == 0 and cos_z.imag == 0:
|
|
529
|
+
raise ZeroDivisionError("Cosine of the complex number is zero, cannot compute tangent")
|
|
530
|
+
return self.sin() / cos_z
|
|
531
|
+
|
|
532
|
+
def cot(self):
|
|
533
|
+
sin_z = self.sin()
|
|
534
|
+
if sin_z.real == 0 and sin_z.imag == 0:
|
|
535
|
+
raise ZeroDivisionError("Sine of the complex number is zero, cannot compute cotangent")
|
|
536
|
+
return self.cos() / sin_z
|
|
537
|
+
|
|
538
|
+
def sec(self):
|
|
539
|
+
cos_z = self.cos()
|
|
540
|
+
if cos_z.real == 0 and cos_z.imag == 0:
|
|
541
|
+
raise ZeroDivisionError("Cosine of the complex number is zero, cannot compute secant")
|
|
542
|
+
return MPComplex(1, 0, self.sigfigs) / cos_z
|
|
543
|
+
|
|
544
|
+
def csc(self):
|
|
545
|
+
sin_z = self.sin()
|
|
546
|
+
if sin_z.real == 0 and sin_z.imag == 0:
|
|
547
|
+
raise ZeroDivisionError("Sine of the complex number is zero, cannot compute cosecant")
|
|
548
|
+
return MPComplex(1, 0, self.sigfigs) / sin_z
|
|
549
|
+
|
|
516
550
|
|
|
517
551
|
def _remove_trailing_zeros(value: Any) -> str:
|
|
518
552
|
value_str = str(value).lower()
|
pypynum/test.py
CHANGED
|
@@ -323,19 +323,8 @@ for _ in list(globals().keys()):
|
|
|
323
323
|
del _
|
|
324
324
|
|
|
325
325
|
print("""\033[91m
|
|
326
|
-
# 提示:
|
|
327
|
-
#
|
|
328
|
-
# 测试已成功通过并结束。
|
|
329
|
-
#
|
|
330
|
-
# 这些测试只是这个包功能的一部分。
|
|
331
|
-
#
|
|
332
|
-
# 更多的功能需要自己探索和尝试!
|
|
333
|
-
#
|
|
334
326
|
# Tip:
|
|
335
|
-
#
|
|
336
327
|
# The test has been successfully passed and ended.
|
|
337
|
-
#
|
|
338
328
|
# These tests are only part of the functionality of this package.
|
|
339
|
-
#
|
|
340
329
|
# More features need to be explored and tried by yourself!
|
|
341
330
|
\033[m""")
|
pypynum/tools.py
CHANGED
|
@@ -409,6 +409,39 @@ def magic_square(n):
|
|
|
409
409
|
return result
|
|
410
410
|
|
|
411
411
|
|
|
412
|
+
def levenshtein_distance(s1: str, s2: str) -> int:
|
|
413
|
+
"""
|
|
414
|
+
Introduction
|
|
415
|
+
==========
|
|
416
|
+
Calculate the Levenshtein distance between two strings.
|
|
417
|
+
|
|
418
|
+
The Levenshtein distance is a measure of the difference between two strings. It is defined as the minimum number
|
|
419
|
+
of single-character edits (i.e., insertions, deletions or substitutions) required to change one string into the
|
|
420
|
+
other.
|
|
421
|
+
|
|
422
|
+
Example
|
|
423
|
+
==========
|
|
424
|
+
>>> levenshtein_distance("kitten", "sitting")
|
|
425
|
+
3
|
|
426
|
+
>>>
|
|
427
|
+
:param s1: First string to compare.
|
|
428
|
+
:param s2: Second string to compare.
|
|
429
|
+
:return: The Levenshtein distance between the two strings.
|
|
430
|
+
"""
|
|
431
|
+
if len(s1) > len(s2):
|
|
432
|
+
s1, s2 = s2, s1
|
|
433
|
+
previous_row = list(range(len(s1) + 1))
|
|
434
|
+
for i2, c2 in enumerate(s2):
|
|
435
|
+
current_row = [i2 + 1]
|
|
436
|
+
for i1, c1 in enumerate(s1):
|
|
437
|
+
insertions = previous_row[i1 + 1] + 1
|
|
438
|
+
deletions = current_row[i1] + 1
|
|
439
|
+
substitutions = previous_row[i1] + (c1 != c2)
|
|
440
|
+
current_row.append(min(insertions, deletions, substitutions))
|
|
441
|
+
previous_row = current_row
|
|
442
|
+
return previous_row[-1]
|
|
443
|
+
|
|
444
|
+
|
|
412
445
|
if __name__ == "__main__":
|
|
413
446
|
import doctest
|
|
414
447
|
|
|
File without changes
|
|
File without changes
|