PyPyNum 1.9.0__py3-none-any.whl → 1.9.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.9.0.dist-info → PyPyNum-1.9.1.dist-info}/METADATA +55 -91
- {PyPyNum-1.9.0.dist-info → PyPyNum-1.9.1.dist-info}/RECORD +13 -12
- pypynum/Array.py +45 -6
- pypynum/README.md +54 -90
- pypynum/__init__.py +1 -1
- pypynum/cipher.py +67 -0
- pypynum/maths.py +30 -27
- pypynum/plotting.py +10 -27
- pypynum/regression.py +2 -4
- pypynum/test.py +2 -3
- pypynum/ufuncs.py +26 -0
- {PyPyNum-1.9.0.dist-info → PyPyNum-1.9.1.dist-info}/WHEEL +0 -0
- {PyPyNum-1.9.0.dist-info → PyPyNum-1.9.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.9.
|
|
3
|
+
Version: 1.9.1
|
|
4
4
|
Summary: A multifunctional mathematical calculation package written in pure Python programming language [Python>=3.4]
|
|
5
5
|
Home-page: https://github.com/PythonSJL/PyPyNum
|
|
6
6
|
Author: Shen Jiayi
|
|
@@ -692,7 +692,7 @@ Description-Content-Type: text/markdown
|
|
|
692
692
|
[](https://pepy.tech/project/pypynum)
|
|
693
693
|
[](https://pepy.tech/project/pypynum)
|
|
694
694
|
|
|
695
|
-
## Version -> 1.9.
|
|
695
|
+
## Version -> 1.9.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
|
|
696
696
|
|
|
697
697
|

|
|
698
698
|
|
|
@@ -789,61 +789,11 @@ Python interpreter and run it!
|
|
|
789
789
|
```
|
|
790
790
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
791
791
|
|
|
792
|
-
|
|
792
|
+
修复了一些功能问题
|
|
793
793
|
|
|
794
|
-
|
|
795
|
-
about 300.
|
|
794
|
+
Fixed some functional issues
|
|
796
795
|
|
|
797
796
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
798
|
-
|
|
799
|
-
以下函数进行了改名,使用时请注意。
|
|
800
|
-
|
|
801
|
-
The following functions have
|
|
802
|
-
been renamed, please be careful
|
|
803
|
-
when using them.
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
interpreter -> parse_expr
|
|
807
|
-
deduplicate -> dedup
|
|
808
|
-
interpolation -> interp
|
|
809
|
-
|
|
810
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
811
|
-
|
|
812
|
-
“chi2_cont”是卡方检验函数,支持输入一
|
|
813
|
-
个列联表,返回(chi2,p,dof,
|
|
814
|
-
expected),当自由度为1时可以设置是否
|
|
815
|
-
经过Yates校正。
|
|
816
|
-
|
|
817
|
-
"chi2_cont" is a chi-square
|
|
818
|
-
test function that supports
|
|
819
|
-
entering a contingency table and
|
|
820
|
-
returning (chi2, p, dof,
|
|
821
|
-
expected). When the degree of
|
|
822
|
-
freedom is 1, you can set
|
|
823
|
-
whether to perform Yates
|
|
824
|
-
correction.
|
|
825
|
-
|
|
826
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
827
|
-
|
|
828
|
-
PyPyNum
|
|
829
|
-
├── cipher
|
|
830
|
-
│ └── FUNCTION
|
|
831
|
-
│ ├── atbash(text: str) -> str
|
|
832
|
-
│ ├── base_64(text: str, decrypt: bool) -> str
|
|
833
|
-
│ ├── caesar(text: str, shift: int, decrypt: bool) -> str
|
|
834
|
-
│ ├── morse(text: str, decrypt: bool) -> str
|
|
835
|
-
│ ├── playfair(text: str, key: str, decrypt: bool) -> str
|
|
836
|
-
│ ├── rot13(text: str) -> str
|
|
837
|
-
│ ├── substitution(text: str, sub_map: dict, decrypt: bool) -> str
|
|
838
|
-
│ └── vigenere(text: str, key: str, decrypt: bool) -> str
|
|
839
|
-
├── probability
|
|
840
|
-
│ └── FUNCTION
|
|
841
|
-
│ ├── chi2_cont(contingency: list, calc_p: bool, corr: bool) -> tuple
|
|
842
|
-
│ ├── chi2_pdf(x: typing.Union[int, float], k: typing.Union[int, float]) -> float
|
|
843
|
-
└── utils
|
|
844
|
-
├── CLASS
|
|
845
|
-
│ ├── LinkedList(object)/__init__(self: Any) -> Any
|
|
846
|
-
│ ├── LinkedListNode(object)/__init__(self: Any, value: Any, next_node: Any) -> Any
|
|
847
797
|
```
|
|
848
798
|
|
|
849
799
|
### 运行用时测试
|
|
@@ -873,7 +823,7 @@ PyPyNum
|
|
|
873
823
|
│ │ └── Array(object)/__init__(self: Any, data: Any, check: Any) -> Any
|
|
874
824
|
│ └── FUNCTION
|
|
875
825
|
│ ├── array(data: Any) -> Any
|
|
876
|
-
│ ├── fill(shape: Any, sequence: Any, repeat: Any) -> Any
|
|
826
|
+
│ ├── fill(shape: Any, sequence: Any, repeat: Any, pad: Any) -> Any
|
|
877
827
|
│ ├── function(_array: Any, _function: Any, args: Any) -> Any
|
|
878
828
|
│ ├── get_shape(data: Any) -> Any
|
|
879
829
|
│ ├── is_valid_array(_array: Any, _shape: Any) -> Any
|
|
@@ -1001,8 +951,12 @@ PyPyNum
|
|
|
1001
951
|
│ ├── atbash(text: str) -> str
|
|
1002
952
|
│ ├── base_64(text: str, decrypt: bool) -> str
|
|
1003
953
|
│ ├── caesar(text: str, shift: int, decrypt: bool) -> str
|
|
954
|
+
│ ├── hill256(text: bytes, key: list, decrypt: bool) -> bytes
|
|
955
|
+
│ ├── ksa(key: bytes) -> list
|
|
1004
956
|
│ ├── morse(text: str, decrypt: bool) -> str
|
|
1005
957
|
│ ├── playfair(text: str, key: str, decrypt: bool) -> str
|
|
958
|
+
│ ├── prga(s: list) -> Any
|
|
959
|
+
│ ├── rc4(text: bytes, key: bytes) -> bytes
|
|
1006
960
|
│ ├── rot13(text: str) -> str
|
|
1007
961
|
│ ├── substitution(text: str, sub_map: dict, decrypt: bool) -> str
|
|
1008
962
|
│ └── vigenere(text: str, key: str, decrypt: bool) -> str
|
|
@@ -1102,7 +1056,7 @@ PyPyNum
|
|
|
1102
1056
|
│ ├── tanh(x: typing.Union[int, float]) -> typing.Union[int, float]
|
|
1103
1057
|
│ ├── totient(n: int) -> int
|
|
1104
1058
|
│ ├── var(numbers: typing.Union[list, tuple], dof: int) -> typing.Union[int, float, complex]
|
|
1105
|
-
│ └── zeta(alpha: typing.Union[int, float]) -> float
|
|
1059
|
+
│ └── zeta(alpha: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
1106
1060
|
├── numbers
|
|
1107
1061
|
│ ├── CLASS
|
|
1108
1062
|
│ └── FUNCTION
|
|
@@ -1115,7 +1069,7 @@ PyPyNum
|
|
|
1115
1069
|
│ └── FUNCTION
|
|
1116
1070
|
│ ├── background(right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool) -> typing.Union[list, str]
|
|
1117
1071
|
│ ├── binary(function: Any, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], error: Any, compare: Any, string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
|
|
1118
|
-
│ ├── c_unary(function: Any,
|
|
1072
|
+
│ ├── c_unary(function: Any, projection: str, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
|
|
1119
1073
|
│ ├── change(data: typing.Union[list, str]) -> typing.Union[list, str]
|
|
1120
1074
|
│ ├── color(text: str, rgb: typing.Union[list, tuple]) -> str
|
|
1121
1075
|
│ └── unary(function: Any, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
|
|
@@ -1180,6 +1134,16 @@ PyPyNum
|
|
|
1180
1134
|
├── types
|
|
1181
1135
|
│ ├── CLASS
|
|
1182
1136
|
│ └── FUNCTION
|
|
1137
|
+
├── ufuncs
|
|
1138
|
+
│ ├── CLASS
|
|
1139
|
+
│ └── FUNCTION
|
|
1140
|
+
│ ├── add(x: Any, y: Any) -> Any
|
|
1141
|
+
│ ├── divide(x: Any, y: Any) -> Any
|
|
1142
|
+
│ ├── floor_divide(x: Any, y: Any) -> Any
|
|
1143
|
+
│ ├── modulo(x: Any, y: Any) -> Any
|
|
1144
|
+
│ ├── multiply(x: Any, y: Any) -> Any
|
|
1145
|
+
│ ├── power(x: Any, y: Any, m: Any) -> Any
|
|
1146
|
+
│ └── subtract(x: Any, y: Any) -> Any
|
|
1183
1147
|
└── utils
|
|
1184
1148
|
├── CLASS
|
|
1185
1149
|
│ ├── InfIterator(object)/__init__(self: Any, start: typing.Union[int, float, complex], mode: str, common: typing.Union[int, float, complex]) -> Any
|
|
@@ -1425,7 +1389,7 @@ print(maths.var([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]))
|
|
|
1425
1389
|
plt = plotting.unary(lambda x: x ** 2, top=10, bottom=0, character="+")
|
|
1426
1390
|
print(plt)
|
|
1427
1391
|
print(plotting.binary(lambda x, y: x ** 2 + y ** 2 - 10, right=10, left=0, compare="<=", basic=plotting.change(plt)))
|
|
1428
|
-
print(plotting.c_unary(lambda x: x ** x,
|
|
1392
|
+
print(plotting.c_unary(lambda x: x ** x, right=2, left=-2, top=2, bottom=-2, complexity=20, character="-"))
|
|
1429
1393
|
|
|
1430
1394
|
"""
|
|
1431
1395
|
1.00e+01| + +
|
|
@@ -1466,34 +1430,34 @@ print(plotting.c_unary(lambda x: x ** x, start=-10, end=10, interval=100, right=
|
|
|
1466
1430
|
| +++ +++
|
|
1467
1431
|
0.00e+00|________________________+++________________________
|
|
1468
1432
|
-5.00e+00 0.00e+00 5.00e+00
|
|
1469
|
-
2.00e+00|
|
|
1470
|
-
|
|
|
1471
|
-
|
|
|
1472
|
-
|
|
1473
|
-
|
|
|
1474
|
-
|
|
|
1475
|
-
|
|
|
1476
|
-
|
|
|
1477
|
-
|
|
|
1478
|
-
|
|
|
1479
|
-
|
|
|
1480
|
-
|
|
|
1481
|
-
|
|
|
1482
|
-
0.00e+00|_ _ _ _ _ _ _ _
|
|
1483
|
-
|
|
|
1484
|
-
|
|
|
1485
|
-
|
|
|
1486
|
-
|
|
|
1487
|
-
|
|
|
1488
|
-
|
|
|
1489
|
-
|
|
|
1490
|
-
|
|
|
1491
|
-
|
|
|
1492
|
-
|
|
|
1493
|
-
|
|
1494
|
-
|
|
|
1495
|
-
|
|
|
1496
|
-
-2.00e+00|
|
|
1433
|
+
2.00e+00| - - - - - -
|
|
1434
|
+
| - - - - - - -
|
|
1435
|
+
| - - - - - -
|
|
1436
|
+
|- - - - - - -
|
|
1437
|
+
| - - - - -- - - - -
|
|
1438
|
+
| - - - - - - - - -
|
|
1439
|
+
| - - - - -- - --- -- - -- - - - - -
|
|
1440
|
+
| - - - -- -- - - - -- - - -
|
|
1441
|
+
| - - - - - - - -- - --- --- - - --- -- - -
|
|
1442
|
+
| - - - - - -- ----- -- -- --- -- -- --- -- - -
|
|
1443
|
+
| - - - ------------ ---- - -- -- - --- - - -
|
|
1444
|
+
| - - - - - ----- - -- ----------------------- -- ---- - -- --
|
|
1445
|
+
| - - - - - ---- --------------------------------- - - - - - -
|
|
1446
|
+
0.00e+00|_ _ _ _ _ _ _ _-_-_-_-_---- ------------------------------------_-- _ _ _ _ _ _ _
|
|
1447
|
+
| - - - - ----------------------------------------- -- - - - -
|
|
1448
|
+
| - -- - - -- - - --------------------------------- - - -
|
|
1449
|
+
| - - ---- - - -- --------------------- ----- ---- - -- -
|
|
1450
|
+
| - - -- --------- -- -- - ----- --- -- - - - -
|
|
1451
|
+
| - - - - - - - ---- --- --- --- -- -- --- - - -
|
|
1452
|
+
| - - - - - -- -- -- - - -- -- --
|
|
1453
|
+
| - - - -- - -- -- - - -- - -
|
|
1454
|
+
| - - - - - - - -- - - -- - -
|
|
1455
|
+
| - - - - -- -- - - - - -
|
|
1456
|
+
| - - - - - - - -
|
|
1457
|
+
|- - - - - - - -
|
|
1458
|
+
| - - - - - -
|
|
1459
|
+
| - - - - -
|
|
1460
|
+
-2.00e+00|___________-_________________-___________-_____________________-____________-____
|
|
1497
1461
|
-2.00e+00 0.00e+00 2.00e+00
|
|
1498
1462
|
"""
|
|
1499
1463
|
|
|
@@ -1503,10 +1467,10 @@ print(random.randint(0, 9, [2, 3, 4]))
|
|
|
1503
1467
|
print(random.uniform(0, 9, [2, 3, 4]))
|
|
1504
1468
|
|
|
1505
1469
|
"""
|
|
1506
|
-
[[[
|
|
1507
|
-
[[[0.
|
|
1508
|
-
[[[
|
|
1509
|
-
[[[
|
|
1470
|
+
[[[0.4604088962341266, -1.7729143777833498, -1.027113249139529, -1.367335972424437], [1.5152952392963814, 0.1143532276512219, -2.2478367353916626, 0.770010737736378], [-0.4126751204277065, -2.5483288418244814, -0.8493985529797649, -0.5563319772201964]], [[1.9010219123281087, 0.44289739103266357, -0.7148439667426828, -0.742966218100922], [0.21210379525283574, 1.5466635593995341, -0.4536304781981763, 0.5978046752778463], [-0.802299453332161, -1.0295309618075863, 0.5960990076298143, -0.7956578324150254]]]
|
|
1471
|
+
[[[0.6378288221898551, 0.5667742466043126, 0.4656215108828976, 0.15042085420645113], [0.17290475960349394, 0.7286971110875379, 0.645886619551428, 0.6328537921605502], [0.5626377160935252, 0.41015810474249603, 0.9951566294215863, 0.21679108443018347]], [[0.7747392018966252, 0.5885873225687281, 0.4305122635955937, 0.1102178686782671], [0.6823600514076231, 0.919946966200235, 0.9010988477920265, 0.9324975541841414], [0.026520946245817467, 0.7483826867189314, 0.25799134110551736, 0.7231613737350734]]]
|
|
1472
|
+
[[[5, 5, 4, 2], [2, 0, 9, 6], [9, 2, 0, 0]], [[0, 3, 9, 2], [2, 5, 5, 3], [9, 2, 5, 1]]]
|
|
1473
|
+
[[[4.661185893580614, 6.263504213542613, 1.5982048879385133, 4.592524740685044], [5.915777961319595, 0.7073727896327806, 2.6233256174392263, 4.980453415047565], [2.257336580759053, 8.299789041235444, 5.839322602213961, 3.1890466264933925]], [[8.498155134210208, 4.722625882838601, 4.4036516933236705, 4.313235000904077], [3.7418534910533126, 2.7783464437089305, 8.884554145257127, 3.860087039759355], [4.430653527343895, 0.9625175276439548, 6.813933725727357, 7.910773669181097]]]
|
|
1510
1474
|
"""
|
|
1511
1475
|
|
|
1512
1476
|
print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -1515,7 +1479,7 @@ print(regression.polynomial_regression(list(range(5)), [2, 4, 6, 7, 8], 4))
|
|
|
1515
1479
|
|
|
1516
1480
|
"""
|
|
1517
1481
|
[1.5, 2.4000000000000004]
|
|
1518
|
-
[-0.
|
|
1482
|
+
[-0.21428571428571563, 2.3571428571428625, 1.971428571428569]
|
|
1519
1483
|
[0.08333333334800574, -0.6666666668092494, 1.4166666678382942, 1.1666666648311956, 2.0000000002900613]
|
|
1520
1484
|
"""
|
|
1521
1485
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
pypynum/Array.py,sha256=
|
|
1
|
+
pypynum/Array.py,sha256=tAEBV3z9vv_4hx-ZRZYnIAxLxSjKQBEnE6lbQk5usQ0,8337
|
|
2
2
|
pypynum/FourierT.py,sha256=AtG0tESykzEs4gDsXhcizW7qhQnmw0gjcWcXefBqzhs,1401
|
|
3
3
|
pypynum/Geometry.py,sha256=bJCuif-wHO-t7oHFEE7ntzIdQwzUEbT3mcKgmBV6Wps,13982
|
|
4
4
|
pypynum/Graph.py,sha256=m9iTCNYRCZmAexDzwJ8Y6J7v1aweT-6TZkqh4fOtZDE,10131
|
|
@@ -8,32 +8,33 @@ pypynum/Matrix.py,sha256=vjkz-m90aWDIv2vzXBriyb4vwaZv8tsPYZzPUeUh-Vk,18050
|
|
|
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=LJFWkXJosgL3H4PKZNKWu8WktkgbKA1dU883uqZTtPU,54040
|
|
12
12
|
pypynum/Symbolics.py,sha256=u-Dig3OLs6qoLzxMpTAYJGq5uSWDMvgU13TAHKLyjMY,2768
|
|
13
13
|
pypynum/Tensor.py,sha256=SJzGRNwHZzOgEabt47scccb-plA25-6s01SFyHd6lJo,3801
|
|
14
14
|
pypynum/Tree.py,sha256=MUT9LErZ3ER_cbiga-nOaZC7Hln8jEV8tRca2dRPWmY,2827
|
|
15
15
|
pypynum/Vector.py,sha256=0GSLDmUE0ZWB4JELB4rL6xHhf767wJlSIIdLt2ZpO9M,3526
|
|
16
|
-
pypynum/__init__.py,sha256=
|
|
16
|
+
pypynum/__init__.py,sha256=3F2NrSIWNcdGxBwXITOmEGRFHyXZQHOn7jCQRaQaULM,1917
|
|
17
17
|
pypynum/chars.py,sha256=VcK9w0i73FMCzc-9aIibjdHqyMsofJXdoBq0d8L7Vr0,1001
|
|
18
|
-
pypynum/cipher.py,sha256=
|
|
18
|
+
pypynum/cipher.py,sha256=DaitY3DCoTuzyrXtD8Ap3IYDLhlMc7-o4AJfLlicvB4,10011
|
|
19
19
|
pypynum/constants.py,sha256=xELv4DIKEqBdwF9tUqCmTQVbgVrlrj385ht5eawvshU,1406
|
|
20
20
|
pypynum/equations.py,sha256=Bn1_VjwMnnvzT0mHYI0eAARRqIHuc3IpOfYvzojTPx0,713
|
|
21
21
|
pypynum/errors.py,sha256=I3nh5YD5F_sBoa7hjPJi81goRflbVAZcjtmW7O2BhJk,220
|
|
22
22
|
pypynum/file.py,sha256=rqrPdcX0NOEPM8s40-ymgPKsTn0HKABW-VEh1OtPnsk,3188
|
|
23
|
-
pypynum/maths.py,sha256=
|
|
23
|
+
pypynum/maths.py,sha256=0XVK9pZD4kSWeBFPm_YKO2K-hqnEYfCusiENbJJ91bk,27301
|
|
24
24
|
pypynum/numbers.py,sha256=WOxwwAN3yHakN4eHcVNn35qsfDcgw3UPSblv4woWyDE,6028
|
|
25
|
-
pypynum/plotting.py,sha256=
|
|
25
|
+
pypynum/plotting.py,sha256=mbIYK5TpY1qvuMJrqz4d8bxJEiZww3AI684vSKV-DgU,7781
|
|
26
26
|
pypynum/polynomial.py,sha256=psFukA31Ed4U7hZHcCGWCpYMi8tanTsZl-pUdklikfg,5998
|
|
27
27
|
pypynum/probability.py,sha256=aUHaS7NMIJJWI8vZktgvn1zQKLtjdBiY5d-qwbJ6fGM,3778
|
|
28
28
|
pypynum/random.py,sha256=vfTtyH5yOSKJoSI_-NT_Tg8wC-ZXT0wt34f87oaSpJY,4610
|
|
29
|
-
pypynum/regression.py,sha256=
|
|
29
|
+
pypynum/regression.py,sha256=HNGifq9rhS7JWFO12nvbP978IZaOOAmgibJURpqYV_0,2070
|
|
30
30
|
pypynum/sequence.py,sha256=7NSZm_p_B00KFj5XZrtSm2FXhsowxs0qg_Q_P4pAA8o,7194
|
|
31
|
-
pypynum/test.py,sha256=
|
|
31
|
+
pypynum/test.py,sha256=ph9oBFjwT1DNUAqdEivJfhIaysDsgWxwLFi8Ekx733U,9119
|
|
32
32
|
pypynum/this.py,sha256=oRX1OpMa4NJmQSdEjJxfszEo5FRYlxRiF8OTDRIcdMA,2154
|
|
33
33
|
pypynum/tools.py,sha256=jv-R0fXJ0ptszAyaFwwakyCMFL835p8T20ihvzL4vbc,12665
|
|
34
34
|
pypynum/types.py,sha256=CVWPZo_ACr_QGH5gAOhoG3jK35peiqipu3PH8ScEYHE,181
|
|
35
|
+
pypynum/ufuncs.py,sha256=EMEPCOVr3JGuaPt6zcNSv0-4HVkXPtV7E5Pp2QFyHhM,305
|
|
35
36
|
pypynum/utils.py,sha256=oeHpAMFItWXfKjb0UQITPwMVKZBd3H5JT3R-jBgn2_w,14466
|
|
36
|
-
PyPyNum-1.9.
|
|
37
|
-
PyPyNum-1.9.
|
|
38
|
-
PyPyNum-1.9.
|
|
39
|
-
PyPyNum-1.9.
|
|
37
|
+
PyPyNum-1.9.1.dist-info/METADATA,sha256=escL3_jEWNc63qto-eS0ao399BX-X56vWIbIsEaho4w,95484
|
|
38
|
+
PyPyNum-1.9.1.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
39
|
+
PyPyNum-1.9.1.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
|
|
40
|
+
PyPyNum-1.9.1.dist-info/RECORD,,
|
pypynum/Array.py
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
from .errors import ShapeError
|
|
2
|
+
from .ufuncs import *
|
|
2
3
|
|
|
3
4
|
ArrayError = ShapeError("The shape of the array is invalid")
|
|
5
|
+
MatchError = ShapeError("The shapes of the two arrays do not match")
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
class Array:
|
|
7
9
|
"""
|
|
8
|
-
It is the base class of vectors, matrices, and
|
|
10
|
+
It is the base class of vectors, matrices, and Arrays,
|
|
9
11
|
which does not support operations but has many statistical functions.
|
|
10
12
|
:param data: An array in the form of a list
|
|
11
13
|
:param check: Check the rationality of the input array
|
|
@@ -51,7 +53,7 @@ class Array:
|
|
|
51
53
|
return self.data == other.data
|
|
52
54
|
|
|
53
55
|
def __ne__(self, other):
|
|
54
|
-
return
|
|
56
|
+
return self.data != other.data
|
|
55
57
|
|
|
56
58
|
def __getitem__(self, item):
|
|
57
59
|
return self.data[item]
|
|
@@ -63,6 +65,42 @@ class Array:
|
|
|
63
65
|
def __hash__(self):
|
|
64
66
|
return hash(repr(self.data))
|
|
65
67
|
|
|
68
|
+
def __truediv__(self, other):
|
|
69
|
+
if isinstance(other, Array):
|
|
70
|
+
if self.shape != other.shape:
|
|
71
|
+
raise MatchError
|
|
72
|
+
return Array(fill(self.shape, [t1 / t2 for t1, t2 in zip(self.flatten(), other.flatten())]), False)
|
|
73
|
+
elif isinstance(other, (int, float, complex)):
|
|
74
|
+
return function(self, divide, [other])
|
|
75
|
+
else:
|
|
76
|
+
raise ValueError("Another must be an array or number")
|
|
77
|
+
|
|
78
|
+
def __floordiv__(self, other):
|
|
79
|
+
if isinstance(other, Array):
|
|
80
|
+
if self.shape != other.shape:
|
|
81
|
+
raise MatchError
|
|
82
|
+
return Array(fill(self.shape, [t1 // t2 for t1, t2 in zip(self.flatten(), other.flatten())]), False)
|
|
83
|
+
elif isinstance(other, (int, float, complex)):
|
|
84
|
+
return function(self, floor_divide, [other])
|
|
85
|
+
else:
|
|
86
|
+
raise ValueError("Another must be an array or number")
|
|
87
|
+
|
|
88
|
+
def __mod__(self, other):
|
|
89
|
+
if isinstance(other, Array):
|
|
90
|
+
if self.shape != other.shape:
|
|
91
|
+
raise MatchError
|
|
92
|
+
return Array(fill(self.shape, [t1 % t2 for t1, t2 in zip(self.flatten(), other.flatten())]), False)
|
|
93
|
+
elif isinstance(other, (int, float, complex)):
|
|
94
|
+
return function(self, modulo, [other])
|
|
95
|
+
else:
|
|
96
|
+
raise ValueError("Another must be an array or number")
|
|
97
|
+
|
|
98
|
+
def __pow__(self, _exp, _mod=None):
|
|
99
|
+
if isinstance(_exp, (int, float, complex)) and isinstance(_mod, (int, float, complex, type(None))):
|
|
100
|
+
return function(self, power, [_exp, _mod])
|
|
101
|
+
else:
|
|
102
|
+
raise ValueError()
|
|
103
|
+
|
|
66
104
|
def flatten(self):
|
|
67
105
|
data = self.data
|
|
68
106
|
while isinstance(data[0], list):
|
|
@@ -181,7 +219,7 @@ def zeros_like(_nested_list):
|
|
|
181
219
|
return 0
|
|
182
220
|
|
|
183
221
|
|
|
184
|
-
def fill(shape, sequence=None, repeat=True):
|
|
222
|
+
def fill(shape, sequence=None, repeat=True, pad=0):
|
|
185
223
|
pointer = -1
|
|
186
224
|
length = 1
|
|
187
225
|
for item in shape:
|
|
@@ -189,12 +227,13 @@ def fill(shape, sequence=None, repeat=True):
|
|
|
189
227
|
if sequence is None:
|
|
190
228
|
sequence = list(range(length))
|
|
191
229
|
total = len(sequence)
|
|
230
|
+
last = total - 1
|
|
192
231
|
|
|
193
232
|
def inner(_shape):
|
|
194
233
|
nonlocal pointer
|
|
195
234
|
if len(_shape) == 0:
|
|
196
|
-
if pointer ==
|
|
197
|
-
return
|
|
235
|
+
if pointer == last and not repeat:
|
|
236
|
+
return pad
|
|
198
237
|
pointer += 1
|
|
199
238
|
return sequence[pointer % total]
|
|
200
239
|
else:
|
|
@@ -222,4 +261,4 @@ def function(_array, _function, args=None):
|
|
|
222
261
|
else:
|
|
223
262
|
return _function(_array) if args is None else _function(_array, *args)
|
|
224
263
|
|
|
225
|
-
return type(_array)(inner(data))
|
|
264
|
+
return type(_array)(inner(data), False)
|
pypynum/README.md
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
[](https://pepy.tech/project/pypynum)
|
|
19
19
|
[](https://pepy.tech/project/pypynum)
|
|
20
20
|
|
|
21
|
-
## Version -> 1.9.
|
|
21
|
+
## Version -> 1.9.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
|
|
22
22
|
|
|
23
23
|

|
|
24
24
|
|
|
@@ -115,61 +115,11 @@ Python interpreter and run it!
|
|
|
115
115
|
```
|
|
116
116
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
修复了一些功能问题
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
about 300.
|
|
120
|
+
Fixed some functional issues
|
|
122
121
|
|
|
123
122
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
124
|
-
|
|
125
|
-
以下函数进行了改名,使用时请注意。
|
|
126
|
-
|
|
127
|
-
The following functions have
|
|
128
|
-
been renamed, please be careful
|
|
129
|
-
when using them.
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
interpreter -> parse_expr
|
|
133
|
-
deduplicate -> dedup
|
|
134
|
-
interpolation -> interp
|
|
135
|
-
|
|
136
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
137
|
-
|
|
138
|
-
“chi2_cont”是卡方检验函数,支持输入一
|
|
139
|
-
个列联表,返回(chi2,p,dof,
|
|
140
|
-
expected),当自由度为1时可以设置是否
|
|
141
|
-
经过Yates校正。
|
|
142
|
-
|
|
143
|
-
"chi2_cont" is a chi-square
|
|
144
|
-
test function that supports
|
|
145
|
-
entering a contingency table and
|
|
146
|
-
returning (chi2, p, dof,
|
|
147
|
-
expected). When the degree of
|
|
148
|
-
freedom is 1, you can set
|
|
149
|
-
whether to perform Yates
|
|
150
|
-
correction.
|
|
151
|
-
|
|
152
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
153
|
-
|
|
154
|
-
PyPyNum
|
|
155
|
-
├── cipher
|
|
156
|
-
│ └── FUNCTION
|
|
157
|
-
│ ├── atbash(text: str) -> str
|
|
158
|
-
│ ├── base_64(text: str, decrypt: bool) -> str
|
|
159
|
-
│ ├── caesar(text: str, shift: int, decrypt: bool) -> str
|
|
160
|
-
│ ├── morse(text: str, decrypt: bool) -> str
|
|
161
|
-
│ ├── playfair(text: str, key: str, decrypt: bool) -> str
|
|
162
|
-
│ ├── rot13(text: str) -> str
|
|
163
|
-
│ ├── substitution(text: str, sub_map: dict, decrypt: bool) -> str
|
|
164
|
-
│ └── vigenere(text: str, key: str, decrypt: bool) -> str
|
|
165
|
-
├── probability
|
|
166
|
-
│ └── FUNCTION
|
|
167
|
-
│ ├── chi2_cont(contingency: list, calc_p: bool, corr: bool) -> tuple
|
|
168
|
-
│ ├── chi2_pdf(x: typing.Union[int, float], k: typing.Union[int, float]) -> float
|
|
169
|
-
└── utils
|
|
170
|
-
├── CLASS
|
|
171
|
-
│ ├── LinkedList(object)/__init__(self: Any) -> Any
|
|
172
|
-
│ ├── LinkedListNode(object)/__init__(self: Any, value: Any, next_node: Any) -> Any
|
|
173
123
|
```
|
|
174
124
|
|
|
175
125
|
### 运行用时测试
|
|
@@ -199,7 +149,7 @@ PyPyNum
|
|
|
199
149
|
│ │ └── Array(object)/__init__(self: Any, data: Any, check: Any) -> Any
|
|
200
150
|
│ └── FUNCTION
|
|
201
151
|
│ ├── array(data: Any) -> Any
|
|
202
|
-
│ ├── fill(shape: Any, sequence: Any, repeat: Any) -> Any
|
|
152
|
+
│ ├── fill(shape: Any, sequence: Any, repeat: Any, pad: Any) -> Any
|
|
203
153
|
│ ├── function(_array: Any, _function: Any, args: Any) -> Any
|
|
204
154
|
│ ├── get_shape(data: Any) -> Any
|
|
205
155
|
│ ├── is_valid_array(_array: Any, _shape: Any) -> Any
|
|
@@ -327,8 +277,12 @@ PyPyNum
|
|
|
327
277
|
│ ├── atbash(text: str) -> str
|
|
328
278
|
│ ├── base_64(text: str, decrypt: bool) -> str
|
|
329
279
|
│ ├── caesar(text: str, shift: int, decrypt: bool) -> str
|
|
280
|
+
│ ├── hill256(text: bytes, key: list, decrypt: bool) -> bytes
|
|
281
|
+
│ ├── ksa(key: bytes) -> list
|
|
330
282
|
│ ├── morse(text: str, decrypt: bool) -> str
|
|
331
283
|
│ ├── playfair(text: str, key: str, decrypt: bool) -> str
|
|
284
|
+
│ ├── prga(s: list) -> Any
|
|
285
|
+
│ ├── rc4(text: bytes, key: bytes) -> bytes
|
|
332
286
|
│ ├── rot13(text: str) -> str
|
|
333
287
|
│ ├── substitution(text: str, sub_map: dict, decrypt: bool) -> str
|
|
334
288
|
│ └── vigenere(text: str, key: str, decrypt: bool) -> str
|
|
@@ -428,7 +382,7 @@ PyPyNum
|
|
|
428
382
|
│ ├── tanh(x: typing.Union[int, float]) -> typing.Union[int, float]
|
|
429
383
|
│ ├── totient(n: int) -> int
|
|
430
384
|
│ ├── var(numbers: typing.Union[list, tuple], dof: int) -> typing.Union[int, float, complex]
|
|
431
|
-
│ └── zeta(alpha: typing.Union[int, float]) -> float
|
|
385
|
+
│ └── zeta(alpha: typing.Union[int, float, complex]) -> typing.Union[int, float, complex]
|
|
432
386
|
├── numbers
|
|
433
387
|
│ ├── CLASS
|
|
434
388
|
│ └── FUNCTION
|
|
@@ -441,7 +395,7 @@ PyPyNum
|
|
|
441
395
|
│ └── FUNCTION
|
|
442
396
|
│ ├── background(right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool) -> typing.Union[list, str]
|
|
443
397
|
│ ├── binary(function: Any, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], error: Any, compare: Any, string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
|
|
444
|
-
│ ├── c_unary(function: Any,
|
|
398
|
+
│ ├── c_unary(function: Any, projection: str, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
|
|
445
399
|
│ ├── change(data: typing.Union[list, str]) -> typing.Union[list, str]
|
|
446
400
|
│ ├── color(text: str, rgb: typing.Union[list, tuple]) -> str
|
|
447
401
|
│ └── unary(function: Any, right: typing.Union[int, float], left: typing.Union[int, float], top: typing.Union[int, float], bottom: typing.Union[int, float], complexity: typing.Union[int, float], ratio: typing.Union[int, float], string: bool, basic: list, character: str, data: bool, coloration: Any) -> typing.Union[list, str]
|
|
@@ -506,6 +460,16 @@ PyPyNum
|
|
|
506
460
|
├── types
|
|
507
461
|
│ ├── CLASS
|
|
508
462
|
│ └── FUNCTION
|
|
463
|
+
├── ufuncs
|
|
464
|
+
│ ├── CLASS
|
|
465
|
+
│ └── FUNCTION
|
|
466
|
+
│ ├── add(x: Any, y: Any) -> Any
|
|
467
|
+
│ ├── divide(x: Any, y: Any) -> Any
|
|
468
|
+
│ ├── floor_divide(x: Any, y: Any) -> Any
|
|
469
|
+
│ ├── modulo(x: Any, y: Any) -> Any
|
|
470
|
+
│ ├── multiply(x: Any, y: Any) -> Any
|
|
471
|
+
│ ├── power(x: Any, y: Any, m: Any) -> Any
|
|
472
|
+
│ └── subtract(x: Any, y: Any) -> Any
|
|
509
473
|
└── utils
|
|
510
474
|
├── CLASS
|
|
511
475
|
│ ├── InfIterator(object)/__init__(self: Any, start: typing.Union[int, float, complex], mode: str, common: typing.Union[int, float, complex]) -> Any
|
|
@@ -751,7 +715,7 @@ print(maths.var([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]))
|
|
|
751
715
|
plt = plotting.unary(lambda x: x ** 2, top=10, bottom=0, character="+")
|
|
752
716
|
print(plt)
|
|
753
717
|
print(plotting.binary(lambda x, y: x ** 2 + y ** 2 - 10, right=10, left=0, compare="<=", basic=plotting.change(plt)))
|
|
754
|
-
print(plotting.c_unary(lambda x: x ** x,
|
|
718
|
+
print(plotting.c_unary(lambda x: x ** x, right=2, left=-2, top=2, bottom=-2, complexity=20, character="-"))
|
|
755
719
|
|
|
756
720
|
"""
|
|
757
721
|
1.00e+01| + +
|
|
@@ -792,34 +756,34 @@ print(plotting.c_unary(lambda x: x ** x, start=-10, end=10, interval=100, right=
|
|
|
792
756
|
| +++ +++
|
|
793
757
|
0.00e+00|________________________+++________________________
|
|
794
758
|
-5.00e+00 0.00e+00 5.00e+00
|
|
795
|
-
2.00e+00|
|
|
796
|
-
|
|
|
797
|
-
|
|
|
798
|
-
|
|
799
|
-
|
|
|
800
|
-
|
|
|
801
|
-
|
|
|
802
|
-
|
|
|
803
|
-
|
|
|
804
|
-
|
|
|
805
|
-
|
|
|
806
|
-
|
|
|
807
|
-
|
|
|
808
|
-
0.00e+00|_ _ _ _ _ _ _ _
|
|
809
|
-
|
|
|
810
|
-
|
|
|
811
|
-
|
|
|
812
|
-
|
|
|
813
|
-
|
|
|
814
|
-
|
|
|
815
|
-
|
|
|
816
|
-
|
|
|
817
|
-
|
|
|
818
|
-
|
|
|
819
|
-
|
|
820
|
-
|
|
|
821
|
-
|
|
|
822
|
-
-2.00e+00|
|
|
759
|
+
2.00e+00| - - - - - -
|
|
760
|
+
| - - - - - - -
|
|
761
|
+
| - - - - - -
|
|
762
|
+
|- - - - - - -
|
|
763
|
+
| - - - - -- - - - -
|
|
764
|
+
| - - - - - - - - -
|
|
765
|
+
| - - - - -- - --- -- - -- - - - - -
|
|
766
|
+
| - - - -- -- - - - -- - - -
|
|
767
|
+
| - - - - - - - -- - --- --- - - --- -- - -
|
|
768
|
+
| - - - - - -- ----- -- -- --- -- -- --- -- - -
|
|
769
|
+
| - - - ------------ ---- - -- -- - --- - - -
|
|
770
|
+
| - - - - - ----- - -- ----------------------- -- ---- - -- --
|
|
771
|
+
| - - - - - ---- --------------------------------- - - - - - -
|
|
772
|
+
0.00e+00|_ _ _ _ _ _ _ _-_-_-_-_---- ------------------------------------_-- _ _ _ _ _ _ _
|
|
773
|
+
| - - - - ----------------------------------------- -- - - - -
|
|
774
|
+
| - -- - - -- - - --------------------------------- - - -
|
|
775
|
+
| - - ---- - - -- --------------------- ----- ---- - -- -
|
|
776
|
+
| - - -- --------- -- -- - ----- --- -- - - - -
|
|
777
|
+
| - - - - - - - ---- --- --- --- -- -- --- - - -
|
|
778
|
+
| - - - - - -- -- -- - - -- -- --
|
|
779
|
+
| - - - -- - -- -- - - -- - -
|
|
780
|
+
| - - - - - - - -- - - -- - -
|
|
781
|
+
| - - - - -- -- - - - - -
|
|
782
|
+
| - - - - - - - -
|
|
783
|
+
|- - - - - - - -
|
|
784
|
+
| - - - - - -
|
|
785
|
+
| - - - - -
|
|
786
|
+
-2.00e+00|___________-_________________-___________-_____________________-____________-____
|
|
823
787
|
-2.00e+00 0.00e+00 2.00e+00
|
|
824
788
|
"""
|
|
825
789
|
|
|
@@ -829,10 +793,10 @@ print(random.randint(0, 9, [2, 3, 4]))
|
|
|
829
793
|
print(random.uniform(0, 9, [2, 3, 4]))
|
|
830
794
|
|
|
831
795
|
"""
|
|
832
|
-
[[[
|
|
833
|
-
[[[0.
|
|
834
|
-
[[[
|
|
835
|
-
[[[
|
|
796
|
+
[[[0.4604088962341266, -1.7729143777833498, -1.027113249139529, -1.367335972424437], [1.5152952392963814, 0.1143532276512219, -2.2478367353916626, 0.770010737736378], [-0.4126751204277065, -2.5483288418244814, -0.8493985529797649, -0.5563319772201964]], [[1.9010219123281087, 0.44289739103266357, -0.7148439667426828, -0.742966218100922], [0.21210379525283574, 1.5466635593995341, -0.4536304781981763, 0.5978046752778463], [-0.802299453332161, -1.0295309618075863, 0.5960990076298143, -0.7956578324150254]]]
|
|
797
|
+
[[[0.6378288221898551, 0.5667742466043126, 0.4656215108828976, 0.15042085420645113], [0.17290475960349394, 0.7286971110875379, 0.645886619551428, 0.6328537921605502], [0.5626377160935252, 0.41015810474249603, 0.9951566294215863, 0.21679108443018347]], [[0.7747392018966252, 0.5885873225687281, 0.4305122635955937, 0.1102178686782671], [0.6823600514076231, 0.919946966200235, 0.9010988477920265, 0.9324975541841414], [0.026520946245817467, 0.7483826867189314, 0.25799134110551736, 0.7231613737350734]]]
|
|
798
|
+
[[[5, 5, 4, 2], [2, 0, 9, 6], [9, 2, 0, 0]], [[0, 3, 9, 2], [2, 5, 5, 3], [9, 2, 5, 1]]]
|
|
799
|
+
[[[4.661185893580614, 6.263504213542613, 1.5982048879385133, 4.592524740685044], [5.915777961319595, 0.7073727896327806, 2.6233256174392263, 4.980453415047565], [2.257336580759053, 8.299789041235444, 5.839322602213961, 3.1890466264933925]], [[8.498155134210208, 4.722625882838601, 4.4036516933236705, 4.313235000904077], [3.7418534910533126, 2.7783464437089305, 8.884554145257127, 3.860087039759355], [4.430653527343895, 0.9625175276439548, 6.813933725727357, 7.910773669181097]]]
|
|
836
800
|
"""
|
|
837
801
|
|
|
838
802
|
print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -841,7 +805,7 @@ print(regression.polynomial_regression(list(range(5)), [2, 4, 6, 7, 8], 4))
|
|
|
841
805
|
|
|
842
806
|
"""
|
|
843
807
|
[1.5, 2.4000000000000004]
|
|
844
|
-
[-0.
|
|
808
|
+
[-0.21428571428571563, 2.3571428571428625, 1.971428571428569]
|
|
845
809
|
[0.08333333334800574, -0.6666666668092494, 1.4166666678382942, 1.1666666648311956, 2.0000000002900613]
|
|
846
810
|
"""
|
|
847
811
|
|
pypynum/__init__.py
CHANGED
|
@@ -39,7 +39,7 @@ from . import types
|
|
|
39
39
|
from .utils import OrderedSet, InfIterator, LinkedList
|
|
40
40
|
from .Vector import vec
|
|
41
41
|
|
|
42
|
-
__version__ = "1.9.
|
|
42
|
+
__version__ = "1.9.1"
|
|
43
43
|
print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
|
|
44
44
|
"Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", "GitHub -> https://github.com/PythonSJL/PyPyNum", sep=" | ")
|
|
45
45
|
del math, arr, ite, num, real, geom, ContentError, RandomError, LogicError, InputError, FullError, Union
|
pypynum/cipher.py
CHANGED
|
@@ -201,3 +201,70 @@ def playfair(text: str, key: str, decrypt: bool = False) -> str:
|
|
|
201
201
|
else:
|
|
202
202
|
result += pair
|
|
203
203
|
return result
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def hill256(text: bytes, key: list, decrypt: bool = False) -> bytes:
|
|
207
|
+
from .Array import fill
|
|
208
|
+
from .Matrix import mat
|
|
209
|
+
|
|
210
|
+
def decrypt_key(k):
|
|
211
|
+
try:
|
|
212
|
+
det = round(k.det())
|
|
213
|
+
except ValueError:
|
|
214
|
+
raise ValueError("The key must be a square matrix")
|
|
215
|
+
res = 0
|
|
216
|
+
while res < mod:
|
|
217
|
+
if det * res % mod == 1:
|
|
218
|
+
break
|
|
219
|
+
else:
|
|
220
|
+
res = res + 1
|
|
221
|
+
if res == mod:
|
|
222
|
+
raise ValueError("The key square matrix does not have a multiplicative inverse element")
|
|
223
|
+
return round(k.inv() * det % mod) * res % mod
|
|
224
|
+
|
|
225
|
+
if not isinstance(text, bytes):
|
|
226
|
+
raise TypeError("The input content needs to be encoded as a byte type")
|
|
227
|
+
mod = 0x100
|
|
228
|
+
length = len(text)
|
|
229
|
+
key = mat(key)
|
|
230
|
+
if decrypt:
|
|
231
|
+
key = decrypt_key(key)
|
|
232
|
+
cols = key.cols
|
|
233
|
+
result = key @ mat(fill([cols, length // cols + bool(length % cols)], text, False)) % mod
|
|
234
|
+
return b"".join([result[i][j].to_bytes(1, "big") for i in range(result.rows) for j in range(result.cols)])
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def ksa(key: bytes) -> list:
|
|
238
|
+
if not isinstance(key, bytes):
|
|
239
|
+
raise TypeError("The key needs to be of byte type")
|
|
240
|
+
length = len(key)
|
|
241
|
+
if not length:
|
|
242
|
+
raise ValueError("The key cannot be empty")
|
|
243
|
+
s = list(range(0x100))
|
|
244
|
+
j = 0
|
|
245
|
+
for i in range(0x100):
|
|
246
|
+
j = (j + s[i] + key[i % length]) % 0x100
|
|
247
|
+
s[i], s[j] = s[j], s[i]
|
|
248
|
+
return s
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def prga(s: list):
|
|
252
|
+
i = 0
|
|
253
|
+
j = 0
|
|
254
|
+
while True:
|
|
255
|
+
i = (i + 1) % 0x100
|
|
256
|
+
j = (j + s[i]) % 0x100
|
|
257
|
+
s[i], s[j] = s[j], s[i]
|
|
258
|
+
k = s[(s[i] + s[j]) % 0x100]
|
|
259
|
+
yield k
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def rc4(text: bytes, key: bytes) -> bytes:
|
|
263
|
+
if not isinstance(text, bytes):
|
|
264
|
+
raise TypeError("The input content needs to be encoded as a byte type")
|
|
265
|
+
stream = prga(ksa(key))
|
|
266
|
+
result = bytearray()
|
|
267
|
+
for byte in text:
|
|
268
|
+
k = next(stream)
|
|
269
|
+
result.append(byte ^ k)
|
|
270
|
+
return bytes(result)
|
pypynum/maths.py
CHANGED
|
@@ -433,7 +433,7 @@ def mean(numbers: arr) -> num:
|
|
|
433
433
|
:param numbers: list | tuple
|
|
434
434
|
:return:
|
|
435
435
|
"""
|
|
436
|
-
return
|
|
436
|
+
return math.fsum(numbers) / len(numbers)
|
|
437
437
|
|
|
438
438
|
|
|
439
439
|
def geom_mean(numbers: arr) -> num:
|
|
@@ -467,7 +467,7 @@ def square_mean(numbers: arr) -> num:
|
|
|
467
467
|
:param numbers: list | tuple
|
|
468
468
|
:return:
|
|
469
469
|
"""
|
|
470
|
-
return math.sqrt(
|
|
470
|
+
return math.sqrt(math.fsum(map(lambda n: n * n, numbers)) / len(numbers))
|
|
471
471
|
|
|
472
472
|
|
|
473
473
|
def harm_mean(numbers: arr) -> num:
|
|
@@ -484,7 +484,7 @@ def harm_mean(numbers: arr) -> num:
|
|
|
484
484
|
:param numbers: list | tuple
|
|
485
485
|
:return:
|
|
486
486
|
"""
|
|
487
|
-
return 0 if 0 in numbers else len(numbers) /
|
|
487
|
+
return 0 if 0 in numbers else len(numbers) / math.fsum(map(lambda n: 1 / n, numbers))
|
|
488
488
|
|
|
489
489
|
|
|
490
490
|
def raw_moment(data: arr, order: int) -> float:
|
|
@@ -502,7 +502,7 @@ def raw_moment(data: arr, order: int) -> float:
|
|
|
502
502
|
:param order: integer
|
|
503
503
|
:return:
|
|
504
504
|
"""
|
|
505
|
-
return
|
|
505
|
+
return math.fsum(map(lambda item: item ** order, data)) / len(data)
|
|
506
506
|
|
|
507
507
|
|
|
508
508
|
def central_moment(data: arr, order: int) -> float:
|
|
@@ -521,7 +521,7 @@ def central_moment(data: arr, order: int) -> float:
|
|
|
521
521
|
:return:
|
|
522
522
|
"""
|
|
523
523
|
avg = mean(data)
|
|
524
|
-
return
|
|
524
|
+
return math.fsum(map(lambda item: (item - avg) ** order, data)) / len(data)
|
|
525
525
|
|
|
526
526
|
|
|
527
527
|
def var(numbers: arr, dof: int = 0) -> num:
|
|
@@ -547,7 +547,7 @@ def var(numbers: arr, dof: int = 0) -> num:
|
|
|
547
547
|
d = item - avg
|
|
548
548
|
return d * d
|
|
549
549
|
|
|
550
|
-
return
|
|
550
|
+
return math.fsum(map(inner, numbers)) / (len(numbers) - dof)
|
|
551
551
|
|
|
552
552
|
|
|
553
553
|
def skew(data: arr) -> float:
|
|
@@ -622,7 +622,7 @@ def cov(x: arr, y: arr, dof: int = 0) -> num:
|
|
|
622
622
|
return float("inf")
|
|
623
623
|
mean_x = mean(x)
|
|
624
624
|
mean_y = mean(y)
|
|
625
|
-
return
|
|
625
|
+
return math.fsum([(x_i - mean_x) * (y_i - mean_y) for x_i, y_i in zip(x, y)]) / (len(x) - dof)
|
|
626
626
|
|
|
627
627
|
|
|
628
628
|
def corr_coeff(x: arr, y: arr) -> num:
|
|
@@ -645,9 +645,9 @@ def corr_coeff(x: arr, y: arr) -> num:
|
|
|
645
645
|
n = len(x)
|
|
646
646
|
mean_x = mean(x)
|
|
647
647
|
mean_y = mean(y)
|
|
648
|
-
covariance =
|
|
649
|
-
std_x = math.sqrt(
|
|
650
|
-
std_y = math.sqrt(
|
|
648
|
+
covariance = math.fsum((_x - mean_x) * (_y - mean_y) for _x, _y in zip(x, y)) / n
|
|
649
|
+
std_x = math.sqrt(math.fsum((_x - mean_x) ** 2 for _x in x) / n)
|
|
650
|
+
std_y = math.sqrt(math.fsum((_y - mean_y) ** 2 for _y in y) / n)
|
|
651
651
|
return covariance / (std_x * std_y)
|
|
652
652
|
|
|
653
653
|
|
|
@@ -782,7 +782,7 @@ def definite_integral(f, x_start: real, x_end: real, n: int = 1000000, *args, **
|
|
|
782
782
|
example
|
|
783
783
|
==========
|
|
784
784
|
>>> definite_integral(lambda a: a ** 2, 0, 2)
|
|
785
|
-
2.
|
|
785
|
+
2.6666666666666665
|
|
786
786
|
>>>
|
|
787
787
|
:param f: function
|
|
788
788
|
:param x_start: integer | float
|
|
@@ -793,12 +793,12 @@ def definite_integral(f, x_start: real, x_end: real, n: int = 1000000, *args, **
|
|
|
793
793
|
h = (x_end - x_start) / n
|
|
794
794
|
if args or kwargs:
|
|
795
795
|
s = f(x_start, *args, **kwargs) + f(x_end, *args, **kwargs)
|
|
796
|
-
s +=
|
|
797
|
-
s +=
|
|
796
|
+
s += math.fsum(map(lambda i: 4 * f(x_start + i * h, *args, **kwargs), range(1, n, 2)))
|
|
797
|
+
s += math.fsum(map(lambda i: 2 * f(x_start + i * h, *args, **kwargs), range(2, n - 1, 2)))
|
|
798
798
|
else:
|
|
799
799
|
s = f(x_start) + f(x_end)
|
|
800
|
-
s +=
|
|
801
|
-
s +=
|
|
800
|
+
s += math.fsum(map(lambda i: 4 * f(x_start + i * h), range(1, n, 2)))
|
|
801
|
+
s += math.fsum(map(lambda i: 2 * f(x_start + i * h), range(2, n - 1, 2)))
|
|
802
802
|
return s * h / 3
|
|
803
803
|
|
|
804
804
|
|
|
@@ -894,7 +894,7 @@ def combination(n: int, r: int) -> int:
|
|
|
894
894
|
return product(list(range(n, n - r, -1))) // product(list(range(r, 0, -1)))
|
|
895
895
|
|
|
896
896
|
|
|
897
|
-
def zeta(alpha:
|
|
897
|
+
def zeta(alpha: num) -> num:
|
|
898
898
|
"""
|
|
899
899
|
introduction
|
|
900
900
|
==========
|
|
@@ -904,12 +904,16 @@ def zeta(alpha: real) -> float:
|
|
|
904
904
|
example
|
|
905
905
|
==========
|
|
906
906
|
>>> zeta(3)
|
|
907
|
-
1.
|
|
907
|
+
1.2020569031590942
|
|
908
908
|
>>>
|
|
909
|
-
:param alpha: integer | float
|
|
909
|
+
:param alpha: integer | float | complex
|
|
910
910
|
:return:
|
|
911
911
|
"""
|
|
912
|
-
|
|
912
|
+
seq = map(lambda _: _ ** (-alpha), range(1, 1000000))
|
|
913
|
+
if alpha.imag:
|
|
914
|
+
return sum(seq)
|
|
915
|
+
else:
|
|
916
|
+
return math.fsum(seq)
|
|
913
917
|
|
|
914
918
|
|
|
915
919
|
def gaussian(x: real, _mu: real = 0, _sigma: real = 1) -> float:
|
|
@@ -1041,7 +1045,8 @@ def cumsum(lst: arr) -> list:
|
|
|
1041
1045
|
if not lst:
|
|
1042
1046
|
return []
|
|
1043
1047
|
cumulative_sum = [lst[0]]
|
|
1044
|
-
|
|
1048
|
+
length = len(lst)
|
|
1049
|
+
for i in range(1, length):
|
|
1045
1050
|
cumulative_sum.append(cumulative_sum[i - 1] + lst[i])
|
|
1046
1051
|
return cumulative_sum
|
|
1047
1052
|
|
|
@@ -1063,7 +1068,8 @@ def cumprod(lst: arr) -> list:
|
|
|
1063
1068
|
if not lst:
|
|
1064
1069
|
return []
|
|
1065
1070
|
cumulative_prod = [lst[0]]
|
|
1066
|
-
|
|
1071
|
+
length = len(lst)
|
|
1072
|
+
for i in range(1, length):
|
|
1067
1073
|
cumulative_prod.append(cumulative_prod[i - 1] * lst[i])
|
|
1068
1074
|
return cumulative_prod
|
|
1069
1075
|
|
|
@@ -1210,7 +1216,7 @@ def normalize(data: arr, target: num = 1) -> arr:
|
|
|
1210
1216
|
:param target: integer | float
|
|
1211
1217
|
:return:
|
|
1212
1218
|
"""
|
|
1213
|
-
total =
|
|
1219
|
+
total = math.fsum(data)
|
|
1214
1220
|
if total == 0 or target == 0:
|
|
1215
1221
|
return type(data)([0]) * len(data)
|
|
1216
1222
|
ratio = target / total
|
|
@@ -1235,8 +1241,8 @@ def average(data, weights, expected=False):
|
|
|
1235
1241
|
"""
|
|
1236
1242
|
if expected:
|
|
1237
1243
|
weights = normalize(weights)
|
|
1238
|
-
result =
|
|
1239
|
-
return result if expected else result /
|
|
1244
|
+
result = math.fsum(map(lambda value: value[0] * value[1], zip(data, weights)))
|
|
1245
|
+
return result if expected else result / math.fsum(weights)
|
|
1240
1246
|
|
|
1241
1247
|
|
|
1242
1248
|
def exgcd(a: int, b: int) -> tuple:
|
|
@@ -1353,9 +1359,6 @@ def is_square(n: int) -> bool:
|
|
|
1353
1359
|
:return:
|
|
1354
1360
|
"""
|
|
1355
1361
|
if is_possibly_square(n):
|
|
1356
|
-
if n <= __max:
|
|
1357
|
-
sqrt = math.sqrt(n)
|
|
1358
|
-
return int(sqrt) == sqrt
|
|
1359
1362
|
try:
|
|
1360
1363
|
from math import isqrt as f
|
|
1361
1364
|
except ImportError:
|
pypynum/plotting.py
CHANGED
|
@@ -141,16 +141,12 @@ def binary(function, right: real = 5, left: real = -5, top: real = 5, bottom: re
|
|
|
141
141
|
return [plane, coordinates] if data else plane
|
|
142
142
|
|
|
143
143
|
|
|
144
|
-
def c_unary(function,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
coloration=False) -> thing:
|
|
144
|
+
def c_unary(function, projection: str = "ri", right: real = 5, left: real = -5, top: real = 5, bottom: real = -5,
|
|
145
|
+
complexity: real = 5, ratio: real = 3, string: bool = True, basic: list = None, character: str = ".",
|
|
146
|
+
data: bool = False, coloration=False) -> thing:
|
|
148
147
|
"""
|
|
149
148
|
Draw a graph of a complex function of one variable.
|
|
150
149
|
:param function: function
|
|
151
|
-
:param start: integer | float
|
|
152
|
-
:param end: integer | float
|
|
153
|
-
:param interval: integer | float
|
|
154
150
|
:param projection: string
|
|
155
151
|
:param right: integer | float
|
|
156
152
|
:param left: integer | float
|
|
@@ -165,32 +161,19 @@ def c_unary(function, start: real, end: real, interval: real = 5, projection: st
|
|
|
165
161
|
:param coloration: bool.
|
|
166
162
|
:return:
|
|
167
163
|
"""
|
|
168
|
-
print("\n注意:自变量目前只支持实数范围\n\nNote: The independent variable currently only supports the real range\n")
|
|
169
|
-
if abs(interval) != interval:
|
|
170
|
-
raise ValueError("The interval cannot be less than zero")
|
|
171
164
|
if not isinstance(character, str) or (len(character) != 1 and not coloration):
|
|
172
165
|
raise ValueError("The parameter character must be one character")
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
else:
|
|
176
|
-
x = linspace(left, right, round((right - left) * complexity + 1))
|
|
177
|
-
c = [complex(_) for _ in map(function, x)]
|
|
166
|
+
x = linspace(left, right, round((right - left) * complexity + 1))
|
|
167
|
+
y = linspace(top, bottom, round((top - bottom) * complexity / ratio + 1))
|
|
178
168
|
plane = [_[:] for _ in basic] if basic else background(right, left, top, bottom, complexity, ratio)
|
|
179
|
-
coordinates = []
|
|
180
|
-
for
|
|
169
|
+
coordinates = [((c0, c1), function(complex(c0, c1))) for p1, c1 in enumerate(y) for p0, c0 in enumerate(x)]
|
|
170
|
+
for x, y in coordinates:
|
|
181
171
|
if projection == "ri":
|
|
182
|
-
_c0, _c1 =
|
|
183
|
-
elif projection == "xr":
|
|
184
|
-
_c0, _c1 = p, _.real
|
|
185
|
-
elif projection == "xi":
|
|
186
|
-
_c0, _c1 = p, _.imag
|
|
172
|
+
_c0, _c1 = y.real, y.imag
|
|
187
173
|
else:
|
|
188
|
-
raise ValueError("
|
|
189
|
-
c0, c1 = round((_c0 - left) * complexity)
|
|
190
|
-
(top - _c1) * complexity / ratio)
|
|
174
|
+
raise ValueError("Other modes are currently not supported")
|
|
175
|
+
c0, c1 = round((_c0 - left) * complexity), round((top - _c1) * complexity / ratio)
|
|
191
176
|
if 0 <= c0 <= len(plane[0]) - 12 and 0 <= c1 <= len(plane) - 2:
|
|
192
|
-
if data:
|
|
193
|
-
coordinates.append((x[p], _.real, _.imag))
|
|
194
177
|
plane[c1][c0 + 11] = character
|
|
195
178
|
if string:
|
|
196
179
|
plane = change(plane)
|
pypynum/regression.py
CHANGED
|
@@ -51,9 +51,7 @@ def polynomial_regression(x: arr, y: arr, n: int = None) -> list:
|
|
|
51
51
|
if not isinstance(n, int) or n <= 0:
|
|
52
52
|
raise ValueError("The degree of a polynomial must be a natural number")
|
|
53
53
|
m = len(x)
|
|
54
|
-
_x = [[_ ** n for _ in x]]
|
|
55
|
-
|
|
56
|
-
_x += [[_ ** (n - i - 1) for _ in x]]
|
|
57
|
-
_x += [[1] * m]
|
|
54
|
+
_x = [[_ ** (n - i) for _ in x] for i in range(n)]
|
|
55
|
+
_x.append([1] * m)
|
|
58
56
|
_x = mat(_x)
|
|
59
57
|
return ((_x @ _x.t()).inv() @ _x @ mat([y]).t()).flatten()
|
pypynum/test.py
CHANGED
|
@@ -268,14 +268,13 @@ print("""\033[92m
|
|
|
268
268
|
plt = plotting.unary(lambda x: x ** 2, top=10, bottom=0, character="+")
|
|
269
269
|
print(plt)
|
|
270
270
|
print(plotting.binary(lambda x, y: x ** 2 + y ** 2 - 10, right=10, left=0, compare="<=", basic=plotting.change(plt)))
|
|
271
|
-
print(plotting.c_unary(lambda x: x ** x,
|
|
271
|
+
print(plotting.c_unary(lambda x: x ** x, right=2, left=-2, top=2, bottom=-2, complexity=20, character="-"))
|
|
272
272
|
\033[m""")
|
|
273
273
|
print("\"\"\"")
|
|
274
274
|
plt = plotting.unary(lambda x: x ** 2, top=10, bottom=0, character="+")
|
|
275
275
|
print(plt)
|
|
276
276
|
print(plotting.binary(lambda x, y: x ** 2 + y ** 2 - 10, right=10, left=0, compare="<=", basic=plotting.change(plt)))
|
|
277
|
-
print(plotting.c_unary(lambda x: x ** x,
|
|
278
|
-
complexity=20, character="-"))
|
|
277
|
+
print(plotting.c_unary(lambda x: x ** x, right=2, left=-2, top=2, bottom=-2, complexity=20, character="-"))
|
|
279
278
|
print("\"\"\"")
|
|
280
279
|
|
|
281
280
|
# random
|
pypynum/ufuncs.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
def add(x, y):
|
|
2
|
+
return x + y
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def subtract(x, y):
|
|
6
|
+
return x - y
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def multiply(x, y):
|
|
10
|
+
return x * y
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def divide(x, y):
|
|
14
|
+
return x / y
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def floor_divide(x, y):
|
|
18
|
+
return x // y
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def modulo(x, y):
|
|
22
|
+
return x % y
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def power(x, y, m=None):
|
|
26
|
+
return pow(x, y, m)
|
|
File without changes
|
|
File without changes
|