PyPyNum 1.8.0__tar.gz → 1.8.1__tar.gz
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.8.0 → PyPyNum-1.8.1}/PKG-INFO +30 -87
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/PyPyNum.egg-info/PKG-INFO +30 -87
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/PyPyNum.egg-info/SOURCES.txt +0 -1
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Matrix.py +236 -32
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/README.md +29 -86
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/__init__.py +2 -2
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/equations.py +3 -4
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/maths.py +6 -1
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/plotting.py +1 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/setup.py +9 -17
- PyPyNum-1.8.0/pypynum/__temporary.py +0 -169
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/PyPyNum.egg-info/dependency_links.txt +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/PyPyNum.egg-info/top_level.txt +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Array.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/FourierT.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Geometry.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Graph.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Group.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Logic.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/NeuralN.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/PyPyNum.png +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Quaternion.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Symbolics.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Tensor.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Tree.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/Vector.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/chars.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/cipher.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/constants.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/errors.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/file.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/numbers.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/polynomial.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/probability.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/random.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/regression.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/sequence.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/test.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/this.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/tools.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/types.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/pypynum/utils.py +0 -0
- {PyPyNum-1.8.0 → PyPyNum-1.8.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyPyNum
|
|
3
|
-
Version: 1.8.
|
|
3
|
+
Version: 1.8.1
|
|
4
4
|
Summary: A multifunctional mathematical calculation package written in pure Python programming language [Python>=3.5]
|
|
5
5
|
Home-page: https://www.gitee.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.8.
|
|
695
|
+
## Version -> 1.8.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
|
|
696
696
|
|
|
697
697
|

|
|
698
698
|
|
|
@@ -741,65 +741,11 @@ Python interpreter and run it!)
|
|
|
741
741
|
```
|
|
742
742
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
743
743
|
|
|
744
|
-
|
|
744
|
+
eig函数修复了计算错误并改名为eigen
|
|
745
745
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
新增函数“magic_square”的功能简介:可
|
|
751
|
-
以生成任意大于等于三的整数阶幻方。
|
|
752
|
-
|
|
753
|
-
Introduction to the newly added
|
|
754
|
-
function "magic square": It can
|
|
755
|
-
generate any integer order magic
|
|
756
|
-
square greater than or equal to
|
|
757
|
-
three.
|
|
758
|
-
|
|
759
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
760
|
-
|
|
761
|
-
新增模块“Graph”的功能简介:具有有向图
|
|
762
|
-
、无向图、带权有向图、带权无向图这四个对
|
|
763
|
-
象,支持添加或删除顶点和边,以及深度优先
|
|
764
|
-
搜索与广度优先搜索这两种图的遍历方式,还
|
|
765
|
-
有计算最短路径等功能。
|
|
766
|
-
|
|
767
|
-
Introduction to the functions of
|
|
768
|
-
the newly added module "Graph":
|
|
769
|
-
it has four objects: directed
|
|
770
|
-
graph, undirected graph,
|
|
771
|
-
weighted directed graph, and
|
|
772
|
-
weighted undirected graph. It
|
|
773
|
-
supports adding or removing
|
|
774
|
-
vertices and edges, as well as
|
|
775
|
-
depth first search and breadth
|
|
776
|
-
first search for graph
|
|
777
|
-
traversal. It also has functions
|
|
778
|
-
such as calculating the shortest
|
|
779
|
-
path.
|
|
780
|
-
|
|
781
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
782
|
-
|
|
783
|
-
新增模块“polynomial”的功能简介:有一
|
|
784
|
-
个多项式对象,可以通过传入包含“(次数,
|
|
785
|
-
系数)”的二元组组成的序列创建多项式对象
|
|
786
|
-
,可以随时设置某一项的数值,并且支持多
|
|
787
|
-
项式形式的四则运算,还有取商式、取余式
|
|
788
|
-
、求幂、求模幂的功能。
|
|
789
|
-
|
|
790
|
-
Introduction to the newly added
|
|
791
|
-
module "polynomial": There is a
|
|
792
|
-
polynomial object that can be
|
|
793
|
-
created by passing in a sequence
|
|
794
|
-
of binary tuples containing
|
|
795
|
-
"degree, coefficient". The value
|
|
796
|
-
of a certain term can be set at
|
|
797
|
-
any time, and it supports
|
|
798
|
-
polynomial form arithmetic
|
|
799
|
-
operations. It also has
|
|
800
|
-
functions such as quotient,
|
|
801
|
-
remainder, exponentiation, and
|
|
802
|
-
modular exponentiation.
|
|
746
|
+
The eig function fixed
|
|
747
|
+
calculation errors and changed
|
|
748
|
+
its name to eigen
|
|
803
749
|
|
|
804
750
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
805
751
|
|
|
@@ -808,23 +754,13 @@ modular exponentiation.
|
|
|
808
754
|
<<<The ellipsis in the following structure represents the original part>>>
|
|
809
755
|
|
|
810
756
|
PyPyNum
|
|
811
|
-
★
|
|
812
|
-
CLASSES
|
|
813
|
-
BaseGraph
|
|
814
|
-
BaseWeGraph
|
|
815
|
-
WeDiGraph
|
|
816
|
-
WeUnGraph
|
|
817
|
-
DiGraph
|
|
818
|
-
UnGraph
|
|
819
|
-
★ polynomial [Polynomial object]
|
|
820
|
-
CLASSES
|
|
821
|
-
Polynomial
|
|
822
|
-
FUNCTIONS
|
|
823
|
-
poly(terms=None)
|
|
824
|
-
★ tools [Other useful tools]
|
|
757
|
+
★ Matrix [Matrix calculation]
|
|
825
758
|
FUNCTIONS
|
|
826
759
|
...
|
|
827
|
-
|
|
760
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
761
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
762
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
763
|
+
...
|
|
828
764
|
```
|
|
829
765
|
|
|
830
766
|
### 运行用时测试
|
|
@@ -939,14 +875,16 @@ PyPyNum
|
|
|
939
875
|
CLASSES
|
|
940
876
|
Matrix
|
|
941
877
|
FUNCTIONS
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
878
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
879
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
880
|
+
identity(n: int) -> pypynum.Matrix.Matrix
|
|
881
|
+
lu(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
945
882
|
mat(data)
|
|
946
|
-
qr(matrix)
|
|
883
|
+
qr(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
884
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
947
885
|
same(rows, cols, value=0)
|
|
948
|
-
svd(matrix)
|
|
949
|
-
tril_indices(n, k=0, m=None)
|
|
886
|
+
svd(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
887
|
+
tril_indices(n: int, k: int = 0, m: int = None) -> tuple
|
|
950
888
|
zeros(_dimensions)
|
|
951
889
|
zeros_like(_nested_list)
|
|
952
890
|
★ NeuralN [A simple neural network model]
|
|
@@ -1130,6 +1068,9 @@ PyPyNum
|
|
|
1130
1068
|
average(data, weights, expected=False)
|
|
1131
1069
|
exgcd(a: int, b: int) -> tuple
|
|
1132
1070
|
crt(n: arr, a: arr) -> int
|
|
1071
|
+
isqrt(x: int) -> int
|
|
1072
|
+
is_possibly_square(n: int) -> bool
|
|
1073
|
+
is_square(n: int) -> bool
|
|
1133
1074
|
★ numbers [Conversion of various numbers]
|
|
1134
1075
|
FUNCTIONS
|
|
1135
1076
|
float2fraction(number: float, mixed: bool = False, error: float = 1e-15) -> tuple
|
|
@@ -1359,7 +1300,7 @@ print(v1.angles())
|
|
|
1359
1300
|
6.62607015e-34
|
|
1360
1301
|
1.618033988749895
|
|
1361
1302
|
3.141592653589793
|
|
1362
|
-
1000000000000
|
|
1303
|
+
1000000000000
|
|
1363
1304
|
|
|
1364
1305
|
>>> p = [1, -2, -3, 4]
|
|
1365
1306
|
>>> m = [
|
|
@@ -1373,7 +1314,9 @@ print(v1.angles())
|
|
|
1373
1314
|
>>> print(equations.polynomial_equation(p))
|
|
1374
1315
|
>>> print(equations.linear_equation(*m))
|
|
1375
1316
|
|
|
1376
|
-
[(-1.5615528128088307-6.5209667308287455e-24j)
|
|
1317
|
+
[[(-1.5615528128088307-6.5209667308287455e-24j) 0 0]
|
|
1318
|
+
[ 0 (2.5615528128088294+4.456233626665941e-24j) 0]
|
|
1319
|
+
[ 0 0 (1.0000000000000007+3.241554513744382e-25j)]]
|
|
1377
1320
|
[ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
|
|
1378
1321
|
|
|
1379
1322
|
>>> print(maths.cot(constants.pi / 3))
|
|
@@ -1468,10 +1411,10 @@ print(v1.angles())
|
|
|
1468
1411
|
>>> print(random.randint(0, 9, [2, 3, 4]))
|
|
1469
1412
|
>>> print(random.uniform(0, 9, [2, 3, 4]))
|
|
1470
1413
|
|
|
1471
|
-
[[[
|
|
1472
|
-
[[[0.
|
|
1473
|
-
[[[
|
|
1474
|
-
[[[
|
|
1414
|
+
[[[1.524086835643172, -0.20868457467847845, 0.5240261503975477, -0.6439838767682032], [-1.091904210196648, -0.20567633973733265, 1.374424576574523, 0.6563097903476932], [0.2171635934136032, 1.0821030876490199, -0.8410496800310051, -0.8321549344577578]], [[0.5306996954571072, -0.4441704154154241, 1.0481960055260355, 0.39805451821848287], [-0.4006858882593715, -0.06238294764009237, -1.1536673264483728, -0.8063185246185602], [0.3029117113345387, -0.32570360518676644, 0.6608320231980702, 1.7415150171137153]]]
|
|
1415
|
+
[[[0.3736243541521843, 0.8599079983285199, 0.4260061864869946, 0.8441437619796597], [0.8955986631978392, 0.7570336992646656, 0.6706841989644684, 0.328634366074538], [0.4371430562585502, 0.9576395263025738, 0.2380278778546957, 0.806813631306664]], [[0.18549375381453237, 0.5749941389233029, 0.7009767023241946, 0.30017399397762223], [0.6661914823434657, 0.7802291606608635, 0.6847755352217044, 0.2661053533652564], [0.07937643994416943, 0.5452043474222034, 0.8026792060861194, 0.07776400257578953]]]
|
|
1416
|
+
[[[9, 0, 9, 0], [2, 6, 3, 4], [5, 8, 4, 7]], [[7, 7, 6, 3], [5, 5, 5, 8], [3, 4, 6, 6]]]
|
|
1417
|
+
[[[5.049093842782947, 1.3880585421884204, 8.533634113864629, 3.550264239771317], [3.3311351975225176, 5.131771033264564, 0.9570872044431911, 5.165536082759862], [1.2035779060925538, 8.292998518472567, 8.014641974770818, 6.251632912237915]], [[6.411677800595937, 5.365937405245105, 8.70943859614565, 4.348757668525482], [7.827612569569748, 1.3718742546020972, 0.5252489627763138, 2.065015517785291], [4.620664668451086, 2.604569735623819, 5.548107842615733, 7.60342292447815]]]
|
|
1475
1418
|
|
|
1476
1419
|
>>> print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
1477
1420
|
>>> print(regression.parabolic_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyPyNum
|
|
3
|
-
Version: 1.8.
|
|
3
|
+
Version: 1.8.1
|
|
4
4
|
Summary: A multifunctional mathematical calculation package written in pure Python programming language [Python>=3.5]
|
|
5
5
|
Home-page: https://www.gitee.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.8.
|
|
695
|
+
## Version -> 1.8.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
|
|
696
696
|
|
|
697
697
|

|
|
698
698
|
|
|
@@ -741,65 +741,11 @@ Python interpreter and run it!)
|
|
|
741
741
|
```
|
|
742
742
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
743
743
|
|
|
744
|
-
|
|
744
|
+
eig函数修复了计算错误并改名为eigen
|
|
745
745
|
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
新增函数“magic_square”的功能简介:可
|
|
751
|
-
以生成任意大于等于三的整数阶幻方。
|
|
752
|
-
|
|
753
|
-
Introduction to the newly added
|
|
754
|
-
function "magic square": It can
|
|
755
|
-
generate any integer order magic
|
|
756
|
-
square greater than or equal to
|
|
757
|
-
three.
|
|
758
|
-
|
|
759
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
760
|
-
|
|
761
|
-
新增模块“Graph”的功能简介:具有有向图
|
|
762
|
-
、无向图、带权有向图、带权无向图这四个对
|
|
763
|
-
象,支持添加或删除顶点和边,以及深度优先
|
|
764
|
-
搜索与广度优先搜索这两种图的遍历方式,还
|
|
765
|
-
有计算最短路径等功能。
|
|
766
|
-
|
|
767
|
-
Introduction to the functions of
|
|
768
|
-
the newly added module "Graph":
|
|
769
|
-
it has four objects: directed
|
|
770
|
-
graph, undirected graph,
|
|
771
|
-
weighted directed graph, and
|
|
772
|
-
weighted undirected graph. It
|
|
773
|
-
supports adding or removing
|
|
774
|
-
vertices and edges, as well as
|
|
775
|
-
depth first search and breadth
|
|
776
|
-
first search for graph
|
|
777
|
-
traversal. It also has functions
|
|
778
|
-
such as calculating the shortest
|
|
779
|
-
path.
|
|
780
|
-
|
|
781
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
782
|
-
|
|
783
|
-
新增模块“polynomial”的功能简介:有一
|
|
784
|
-
个多项式对象,可以通过传入包含“(次数,
|
|
785
|
-
系数)”的二元组组成的序列创建多项式对象
|
|
786
|
-
,可以随时设置某一项的数值,并且支持多
|
|
787
|
-
项式形式的四则运算,还有取商式、取余式
|
|
788
|
-
、求幂、求模幂的功能。
|
|
789
|
-
|
|
790
|
-
Introduction to the newly added
|
|
791
|
-
module "polynomial": There is a
|
|
792
|
-
polynomial object that can be
|
|
793
|
-
created by passing in a sequence
|
|
794
|
-
of binary tuples containing
|
|
795
|
-
"degree, coefficient". The value
|
|
796
|
-
of a certain term can be set at
|
|
797
|
-
any time, and it supports
|
|
798
|
-
polynomial form arithmetic
|
|
799
|
-
operations. It also has
|
|
800
|
-
functions such as quotient,
|
|
801
|
-
remainder, exponentiation, and
|
|
802
|
-
modular exponentiation.
|
|
746
|
+
The eig function fixed
|
|
747
|
+
calculation errors and changed
|
|
748
|
+
its name to eigen
|
|
803
749
|
|
|
804
750
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
805
751
|
|
|
@@ -808,23 +754,13 @@ modular exponentiation.
|
|
|
808
754
|
<<<The ellipsis in the following structure represents the original part>>>
|
|
809
755
|
|
|
810
756
|
PyPyNum
|
|
811
|
-
★
|
|
812
|
-
CLASSES
|
|
813
|
-
BaseGraph
|
|
814
|
-
BaseWeGraph
|
|
815
|
-
WeDiGraph
|
|
816
|
-
WeUnGraph
|
|
817
|
-
DiGraph
|
|
818
|
-
UnGraph
|
|
819
|
-
★ polynomial [Polynomial object]
|
|
820
|
-
CLASSES
|
|
821
|
-
Polynomial
|
|
822
|
-
FUNCTIONS
|
|
823
|
-
poly(terms=None)
|
|
824
|
-
★ tools [Other useful tools]
|
|
757
|
+
★ Matrix [Matrix calculation]
|
|
825
758
|
FUNCTIONS
|
|
826
759
|
...
|
|
827
|
-
|
|
760
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
761
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
762
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
763
|
+
...
|
|
828
764
|
```
|
|
829
765
|
|
|
830
766
|
### 运行用时测试
|
|
@@ -939,14 +875,16 @@ PyPyNum
|
|
|
939
875
|
CLASSES
|
|
940
876
|
Matrix
|
|
941
877
|
FUNCTIONS
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
878
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
879
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
880
|
+
identity(n: int) -> pypynum.Matrix.Matrix
|
|
881
|
+
lu(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
945
882
|
mat(data)
|
|
946
|
-
qr(matrix)
|
|
883
|
+
qr(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
884
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
947
885
|
same(rows, cols, value=0)
|
|
948
|
-
svd(matrix)
|
|
949
|
-
tril_indices(n, k=0, m=None)
|
|
886
|
+
svd(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
887
|
+
tril_indices(n: int, k: int = 0, m: int = None) -> tuple
|
|
950
888
|
zeros(_dimensions)
|
|
951
889
|
zeros_like(_nested_list)
|
|
952
890
|
★ NeuralN [A simple neural network model]
|
|
@@ -1130,6 +1068,9 @@ PyPyNum
|
|
|
1130
1068
|
average(data, weights, expected=False)
|
|
1131
1069
|
exgcd(a: int, b: int) -> tuple
|
|
1132
1070
|
crt(n: arr, a: arr) -> int
|
|
1071
|
+
isqrt(x: int) -> int
|
|
1072
|
+
is_possibly_square(n: int) -> bool
|
|
1073
|
+
is_square(n: int) -> bool
|
|
1133
1074
|
★ numbers [Conversion of various numbers]
|
|
1134
1075
|
FUNCTIONS
|
|
1135
1076
|
float2fraction(number: float, mixed: bool = False, error: float = 1e-15) -> tuple
|
|
@@ -1359,7 +1300,7 @@ print(v1.angles())
|
|
|
1359
1300
|
6.62607015e-34
|
|
1360
1301
|
1.618033988749895
|
|
1361
1302
|
3.141592653589793
|
|
1362
|
-
1000000000000
|
|
1303
|
+
1000000000000
|
|
1363
1304
|
|
|
1364
1305
|
>>> p = [1, -2, -3, 4]
|
|
1365
1306
|
>>> m = [
|
|
@@ -1373,7 +1314,9 @@ print(v1.angles())
|
|
|
1373
1314
|
>>> print(equations.polynomial_equation(p))
|
|
1374
1315
|
>>> print(equations.linear_equation(*m))
|
|
1375
1316
|
|
|
1376
|
-
[(-1.5615528128088307-6.5209667308287455e-24j)
|
|
1317
|
+
[[(-1.5615528128088307-6.5209667308287455e-24j) 0 0]
|
|
1318
|
+
[ 0 (2.5615528128088294+4.456233626665941e-24j) 0]
|
|
1319
|
+
[ 0 0 (1.0000000000000007+3.241554513744382e-25j)]]
|
|
1377
1320
|
[ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
|
|
1378
1321
|
|
|
1379
1322
|
>>> print(maths.cot(constants.pi / 3))
|
|
@@ -1468,10 +1411,10 @@ print(v1.angles())
|
|
|
1468
1411
|
>>> print(random.randint(0, 9, [2, 3, 4]))
|
|
1469
1412
|
>>> print(random.uniform(0, 9, [2, 3, 4]))
|
|
1470
1413
|
|
|
1471
|
-
[[[
|
|
1472
|
-
[[[0.
|
|
1473
|
-
[[[
|
|
1474
|
-
[[[
|
|
1414
|
+
[[[1.524086835643172, -0.20868457467847845, 0.5240261503975477, -0.6439838767682032], [-1.091904210196648, -0.20567633973733265, 1.374424576574523, 0.6563097903476932], [0.2171635934136032, 1.0821030876490199, -0.8410496800310051, -0.8321549344577578]], [[0.5306996954571072, -0.4441704154154241, 1.0481960055260355, 0.39805451821848287], [-0.4006858882593715, -0.06238294764009237, -1.1536673264483728, -0.8063185246185602], [0.3029117113345387, -0.32570360518676644, 0.6608320231980702, 1.7415150171137153]]]
|
|
1415
|
+
[[[0.3736243541521843, 0.8599079983285199, 0.4260061864869946, 0.8441437619796597], [0.8955986631978392, 0.7570336992646656, 0.6706841989644684, 0.328634366074538], [0.4371430562585502, 0.9576395263025738, 0.2380278778546957, 0.806813631306664]], [[0.18549375381453237, 0.5749941389233029, 0.7009767023241946, 0.30017399397762223], [0.6661914823434657, 0.7802291606608635, 0.6847755352217044, 0.2661053533652564], [0.07937643994416943, 0.5452043474222034, 0.8026792060861194, 0.07776400257578953]]]
|
|
1416
|
+
[[[9, 0, 9, 0], [2, 6, 3, 4], [5, 8, 4, 7]], [[7, 7, 6, 3], [5, 5, 5, 8], [3, 4, 6, 6]]]
|
|
1417
|
+
[[[5.049093842782947, 1.3880585421884204, 8.533634113864629, 3.550264239771317], [3.3311351975225176, 5.131771033264564, 0.9570872044431911, 5.165536082759862], [1.2035779060925538, 8.292998518472567, 8.014641974770818, 6.251632912237915]], [[6.411677800595937, 5.365937405245105, 8.70943859614565, 4.348757668525482], [7.827612569569748, 1.3718742546020972, 0.5252489627763138, 2.065015517785291], [4.620664668451086, 2.604569735623819, 5.548107842615733, 7.60342292447815]]]
|
|
1475
1418
|
|
|
1476
1419
|
>>> print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
1477
1420
|
>>> print(regression.parabolic_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -217,13 +217,25 @@ def same(rows, cols, value=0):
|
|
|
217
217
|
return Matrix([[value] * cols for _ in range(rows)])
|
|
218
218
|
|
|
219
219
|
|
|
220
|
-
def
|
|
220
|
+
def rotate90(matrix: Matrix, times: int) -> Matrix:
|
|
221
|
+
matrix = matrix.copy()
|
|
222
|
+
if times % 4 == 0:
|
|
223
|
+
return matrix
|
|
224
|
+
elif times % 4 == 1:
|
|
225
|
+
return Matrix([list(col)[::-1] for col in zip(*matrix)])
|
|
226
|
+
elif times % 4 == 2:
|
|
227
|
+
return Matrix([row[::-1] for row in matrix[::-1]])
|
|
228
|
+
else:
|
|
229
|
+
return Matrix([list(col)[::-1] for col in zip(*matrix[::-1])][::-1])
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def lu(matrix: Matrix) -> tuple:
|
|
221
233
|
rows = matrix.rows
|
|
222
234
|
cols = matrix.cols
|
|
223
235
|
if rows != cols:
|
|
224
236
|
raise SquareError
|
|
225
237
|
L = [[1.0 if a == b else 0.0 for a in range(cols)] for b in range(rows)]
|
|
226
|
-
U = [[float(matrix
|
|
238
|
+
U = [[float(matrix[b][a]) for a in range(cols)] for b in range(rows)]
|
|
227
239
|
for i in range(rows - 1):
|
|
228
240
|
for j in range(i + 1, rows):
|
|
229
241
|
L[j][i] = U[j][i] / U[i][i]
|
|
@@ -235,7 +247,7 @@ def lu(matrix):
|
|
|
235
247
|
return Matrix(L), Matrix(U)
|
|
236
248
|
|
|
237
249
|
|
|
238
|
-
def tril_indices(n, k=0, m=None):
|
|
250
|
+
def tril_indices(n: int, k: int = 0, m: int = None) -> tuple:
|
|
239
251
|
if m is None:
|
|
240
252
|
m = n
|
|
241
253
|
if n < 1 or k <= -n or m < 1:
|
|
@@ -244,11 +256,11 @@ def tril_indices(n, k=0, m=None):
|
|
|
244
256
|
return [y[1] for y in _indices], [x[0] for x in _indices]
|
|
245
257
|
|
|
246
258
|
|
|
247
|
-
def identity(n):
|
|
259
|
+
def identity(n: int) -> Matrix:
|
|
248
260
|
return Matrix([[1.0 if a == b else 0.0 for a in range(n)] for b in range(n)])
|
|
249
261
|
|
|
250
262
|
|
|
251
|
-
def qr(matrix):
|
|
263
|
+
def qr(matrix: Matrix) -> tuple:
|
|
252
264
|
from math import hypot
|
|
253
265
|
r = matrix.rows
|
|
254
266
|
c = matrix.cols
|
|
@@ -273,33 +285,225 @@ def qr(matrix):
|
|
|
273
285
|
return Matrix([[item for item in line] for line in Q]), Matrix([[item for item in line] for line in R])
|
|
274
286
|
|
|
275
287
|
|
|
276
|
-
def
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
288
|
+
def hessenberg(matrix: Matrix) -> tuple:
|
|
289
|
+
from math import sqrt
|
|
290
|
+
a = matrix.copy()
|
|
291
|
+
n = a.rows
|
|
292
|
+
t = [0.0] * n
|
|
293
|
+
a[-1, -1] = float(a[-1, -1])
|
|
294
|
+
if n > 2:
|
|
295
|
+
inf = float("inf")
|
|
296
|
+
for i in range(n - 1, 1, -1):
|
|
297
|
+
scale = 0.0
|
|
298
|
+
for k in range(0, i):
|
|
299
|
+
scale += abs(a[i, k].real) + abs(a[i, k].imag)
|
|
300
|
+
scale_inv = 0.0
|
|
301
|
+
if scale != 0:
|
|
302
|
+
scale_inv = 1 / scale
|
|
303
|
+
if scale == 0 or scale_inv == inf:
|
|
304
|
+
t[i] = 0.0
|
|
305
|
+
a[i, i - 1] = 0.0
|
|
306
|
+
continue
|
|
307
|
+
h = 0.0
|
|
308
|
+
for k in range(0, i):
|
|
309
|
+
a[i, k] = a[i, k] * scale_inv
|
|
310
|
+
rr, ii = a[i, k].real, a[i, k].imag
|
|
311
|
+
h += rr * rr + ii * ii
|
|
312
|
+
f = a[i, i - 1]
|
|
313
|
+
f0 = abs(f)
|
|
314
|
+
g = sqrt(h)
|
|
315
|
+
a[i, i - 1] = - g * scale
|
|
316
|
+
if f0 == 0:
|
|
317
|
+
t[i] = g
|
|
318
|
+
else:
|
|
319
|
+
ff = f / f0
|
|
320
|
+
t[i] = f + g * ff
|
|
321
|
+
a[i, i - 1] = a[i, i - 1] * ff
|
|
322
|
+
h += g * f0
|
|
323
|
+
h = 1 / sqrt(h)
|
|
324
|
+
t[i] *= h
|
|
325
|
+
for k in range(0, i - 1):
|
|
326
|
+
a[i, k] = a[i, k] * h
|
|
327
|
+
for j in range(0, i):
|
|
328
|
+
g = t[i].conjugate() * a[j, i - 1]
|
|
329
|
+
for k in range(0, i - 1):
|
|
330
|
+
g += a[i, k].conjugate() * a[j, k]
|
|
331
|
+
a[j, i - 1] = a[j, i - 1] - g * t[i]
|
|
332
|
+
for k in range(0, i - 1):
|
|
333
|
+
a[j, k] = a[j, k] - g * a[i, k]
|
|
334
|
+
for j in range(0, n):
|
|
335
|
+
g = t[i] * a[i - 1, j]
|
|
336
|
+
for k in range(0, i - 1):
|
|
337
|
+
g += a[i, k] * a[k, j]
|
|
338
|
+
a[i - 1, j] = a[i - 1, j] - g * t[i].conjugate()
|
|
339
|
+
for k in range(0, i - 1):
|
|
340
|
+
a[k, j] = a[k, j] - g * a[i, k].conjugate()
|
|
341
|
+
q = a.copy()
|
|
342
|
+
if n == 1:
|
|
343
|
+
q[0, 0] = 1.0
|
|
344
|
+
return q, a
|
|
345
|
+
q[0, 0] = q[1, 1] = 1.0
|
|
346
|
+
q[0, 1] = q[1, 0] = 0.0
|
|
347
|
+
for i in range(2, n):
|
|
348
|
+
if t[i] != 0:
|
|
349
|
+
for j in range(0, i):
|
|
350
|
+
g = t[i] * q[i - 1, j]
|
|
351
|
+
for k in range(0, i - 1):
|
|
352
|
+
g += q[i, k] * q[k, j]
|
|
353
|
+
q[i - 1, j] -= g * t[i].conjugate()
|
|
354
|
+
for k in range(0, i - 1):
|
|
355
|
+
q[k, j] -= g * a[i, k].conjugate()
|
|
356
|
+
q[i, i] = 1.0
|
|
357
|
+
for j in range(0, i):
|
|
358
|
+
q[j, i] = q[i, j] = 0.0
|
|
359
|
+
for x in range(n):
|
|
360
|
+
for y in range(x + 2, n):
|
|
361
|
+
a[y, x] = 0.0
|
|
362
|
+
return q, a
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def eigen(matrix: Matrix) -> tuple:
|
|
366
|
+
from math import hypot
|
|
367
|
+
from cmath import sqrt
|
|
368
|
+
a = matrix.copy()
|
|
369
|
+
n = a.rows
|
|
370
|
+
if n == 1:
|
|
371
|
+
return Matrix([[float(a[0, 0])]]), Matrix([[1.0]])
|
|
372
|
+
q, a = hessenberg(a)
|
|
373
|
+
norm = 0
|
|
374
|
+
for x in range(n):
|
|
375
|
+
for y in range(min(x + 2, n)):
|
|
376
|
+
norm += abs(a[y, x])
|
|
377
|
+
norm = norm ** 0.5 / n
|
|
378
|
+
if norm == 0:
|
|
379
|
+
return None, None
|
|
380
|
+
n0 = 0
|
|
381
|
+
n1 = n
|
|
382
|
+
its = 0
|
|
383
|
+
while True:
|
|
384
|
+
k = n0
|
|
385
|
+
while k + 1 < n1:
|
|
386
|
+
if abs(a[k + 1, k]) <= 1e-100:
|
|
387
|
+
break
|
|
388
|
+
k += 1
|
|
389
|
+
if k + 1 < n1:
|
|
390
|
+
a[k + 1, k] = 0.0
|
|
391
|
+
n0 = k + 1
|
|
392
|
+
its = 0
|
|
393
|
+
if n0 + 1 >= n1:
|
|
394
|
+
n0 = 0
|
|
395
|
+
n1 = k + 1
|
|
396
|
+
if n1 < 2:
|
|
397
|
+
break
|
|
398
|
+
else:
|
|
399
|
+
if its % 30 == 10:
|
|
400
|
+
shift = a[n1 - 1, n1 - 2]
|
|
401
|
+
elif its % 30 == 20:
|
|
402
|
+
shift = abs(a[n1 - 1, n1 - 2])
|
|
403
|
+
elif its % 30 == 29:
|
|
404
|
+
shift = norm
|
|
405
|
+
else:
|
|
406
|
+
t = a[n1 - 2, n1 - 2] + a[n1 - 1, n1 - 1]
|
|
407
|
+
s = (a[n1 - 1, n1 - 1] - a[n1 - 2, n1 - 2]) ** 2 + 4 * a[n1 - 1, n1 - 2] * a[n1 - 2, n1 - 1]
|
|
408
|
+
if s.real > 0:
|
|
409
|
+
s = sqrt(s)
|
|
410
|
+
else:
|
|
411
|
+
s = sqrt(-s) * 1j
|
|
412
|
+
if s.imag == 0:
|
|
413
|
+
s = s.real
|
|
414
|
+
a0 = (t + s) / 2
|
|
415
|
+
b0 = (t - s) / 2
|
|
416
|
+
if abs(a[n1 - 1, n1 - 1] - a0) > abs(a[n1 - 1, n1 - 1] - b0):
|
|
417
|
+
shift = b0
|
|
418
|
+
else:
|
|
419
|
+
shift = a0
|
|
420
|
+
its += 1
|
|
421
|
+
c = a[n0, n0] - shift
|
|
422
|
+
s = a[n0 + 1, n0]
|
|
423
|
+
v = hypot(abs(c), abs(s))
|
|
424
|
+
if v == 0:
|
|
425
|
+
c = 1
|
|
426
|
+
s = 0
|
|
427
|
+
else:
|
|
428
|
+
c /= v
|
|
429
|
+
s /= v
|
|
430
|
+
cc = c.conjugate()
|
|
431
|
+
cs = s.conjugate()
|
|
432
|
+
for k in range(n0, n):
|
|
433
|
+
x = a[n0, k]
|
|
434
|
+
y = a[n0 + 1, k]
|
|
435
|
+
a[n0, k] = cc * x + cs * y
|
|
436
|
+
a[n0 + 1, k] = c * y - s * x
|
|
437
|
+
for k in range(min(n1, n0 + 3)):
|
|
438
|
+
x = a[k, n0]
|
|
439
|
+
y = a[k, n0 + 1]
|
|
440
|
+
a[k, n0] = c * x + s * y
|
|
441
|
+
a[k, n0 + 1] = cc * y - cs * x
|
|
442
|
+
if not isinstance(q, bool):
|
|
443
|
+
for k in range(n):
|
|
444
|
+
x = q[k, n0]
|
|
445
|
+
y = q[k, n0 + 1]
|
|
446
|
+
q[k, n0] = c * x + s * y
|
|
447
|
+
q[k, n0 + 1] = cc * y - cs * x
|
|
448
|
+
for j in range(n0, n1 - 2):
|
|
449
|
+
c = a[j + 1, j]
|
|
450
|
+
s = a[j + 2, j]
|
|
451
|
+
v = hypot(abs(c), abs(s))
|
|
452
|
+
if v == 0:
|
|
453
|
+
a[j + 1, j] = 0.0
|
|
454
|
+
c = 1
|
|
455
|
+
s = 0
|
|
456
|
+
else:
|
|
457
|
+
a[j + 1, j] = v
|
|
458
|
+
c /= v
|
|
459
|
+
s /= v
|
|
460
|
+
a[j + 2, j] = 0.0
|
|
461
|
+
cc = c.conjugate()
|
|
462
|
+
cs = s.conjugate()
|
|
463
|
+
for k in range(j + 1, n):
|
|
464
|
+
x = a[j + 1, k]
|
|
465
|
+
y = a[j + 2, k]
|
|
466
|
+
a[j + 1, k] = cc * x + cs * y
|
|
467
|
+
a[j + 2, k] = c * y - s * x
|
|
468
|
+
for k in range(0, min(n1, j + 4)):
|
|
469
|
+
x = a[k, j + 1]
|
|
470
|
+
y = a[k, j + 2]
|
|
471
|
+
a[k, j + 1] = c * x + s * y
|
|
472
|
+
a[k, j + 2] = cc * y - cs * x
|
|
473
|
+
if not isinstance(q, bool):
|
|
474
|
+
for k in range(0, n):
|
|
475
|
+
x = q[k, j + 1]
|
|
476
|
+
y = q[k, j + 2]
|
|
477
|
+
q[k, j + 1] = c * x + s * y
|
|
478
|
+
q[k, j + 2] = cc * y - cs * x
|
|
479
|
+
e = Matrix([[a[i, i] if j == i else 0 for j in range(n)] for i in range(n)])
|
|
480
|
+
er = identity(n)
|
|
481
|
+
m = 1
|
|
482
|
+
for i in range(1, n):
|
|
483
|
+
s = a[i, i]
|
|
484
|
+
for j in range(i - 1, -1, -1):
|
|
485
|
+
r = 0
|
|
486
|
+
for k in range(j + 1, i + 1):
|
|
487
|
+
r += a[j, k] * er[k, i]
|
|
488
|
+
t = a[j, j] - s
|
|
489
|
+
r = -r / t
|
|
490
|
+
er[j, i] = r
|
|
491
|
+
m = max(m, abs(r))
|
|
492
|
+
if m != 1:
|
|
493
|
+
for k in range(0, i + 1):
|
|
494
|
+
er[k, i] /= m
|
|
495
|
+
q = q @ er
|
|
496
|
+
return e, q
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def svd(matrix: Matrix) -> tuple:
|
|
500
|
+
print("\n警告:SVD函数可能存在计算错误\n\nWarning: The SVD function may have calculation errors\n")
|
|
501
|
+
e0, u = eigen(matrix @ matrix.t())
|
|
502
|
+
u = Matrix([_[::-1] for _ in u])
|
|
503
|
+
e1, v = eigen(matrix.t() @ matrix)
|
|
504
|
+
sigma = Matrix([[((e0[i, i] + e1[i, i]) / 2) ** 0.5 if j == i else 0 for j in range(matrix.cols - 1, -1, -1)]
|
|
505
|
+
for i in range(matrix.rows - 1, -1, -1)])
|
|
506
|
+
return u, sigma, v.t()
|
|
303
507
|
|
|
304
508
|
|
|
305
509
|
del Array
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
[](https://pepy.tech/project/pypynum)
|
|
19
19
|
[](https://pepy.tech/project/pypynum)
|
|
20
20
|
|
|
21
|
-
## Version -> 1.8.
|
|
21
|
+
## Version -> 1.8.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
|
|
22
22
|
|
|
23
23
|

|
|
24
24
|
|
|
@@ -67,65 +67,11 @@ Python interpreter and run it!)
|
|
|
67
67
|
```
|
|
68
68
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
69
69
|
|
|
70
|
-
|
|
70
|
+
eig函数修复了计算错误并改名为eigen
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
新增函数“magic_square”的功能简介:可
|
|
77
|
-
以生成任意大于等于三的整数阶幻方。
|
|
78
|
-
|
|
79
|
-
Introduction to the newly added
|
|
80
|
-
function "magic square": It can
|
|
81
|
-
generate any integer order magic
|
|
82
|
-
square greater than or equal to
|
|
83
|
-
three.
|
|
84
|
-
|
|
85
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
86
|
-
|
|
87
|
-
新增模块“Graph”的功能简介:具有有向图
|
|
88
|
-
、无向图、带权有向图、带权无向图这四个对
|
|
89
|
-
象,支持添加或删除顶点和边,以及深度优先
|
|
90
|
-
搜索与广度优先搜索这两种图的遍历方式,还
|
|
91
|
-
有计算最短路径等功能。
|
|
92
|
-
|
|
93
|
-
Introduction to the functions of
|
|
94
|
-
the newly added module "Graph":
|
|
95
|
-
it has four objects: directed
|
|
96
|
-
graph, undirected graph,
|
|
97
|
-
weighted directed graph, and
|
|
98
|
-
weighted undirected graph. It
|
|
99
|
-
supports adding or removing
|
|
100
|
-
vertices and edges, as well as
|
|
101
|
-
depth first search and breadth
|
|
102
|
-
first search for graph
|
|
103
|
-
traversal. It also has functions
|
|
104
|
-
such as calculating the shortest
|
|
105
|
-
path.
|
|
106
|
-
|
|
107
|
-
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
108
|
-
|
|
109
|
-
新增模块“polynomial”的功能简介:有一
|
|
110
|
-
个多项式对象,可以通过传入包含“(次数,
|
|
111
|
-
系数)”的二元组组成的序列创建多项式对象
|
|
112
|
-
,可以随时设置某一项的数值,并且支持多
|
|
113
|
-
项式形式的四则运算,还有取商式、取余式
|
|
114
|
-
、求幂、求模幂的功能。
|
|
115
|
-
|
|
116
|
-
Introduction to the newly added
|
|
117
|
-
module "polynomial": There is a
|
|
118
|
-
polynomial object that can be
|
|
119
|
-
created by passing in a sequence
|
|
120
|
-
of binary tuples containing
|
|
121
|
-
"degree, coefficient". The value
|
|
122
|
-
of a certain term can be set at
|
|
123
|
-
any time, and it supports
|
|
124
|
-
polynomial form arithmetic
|
|
125
|
-
operations. It also has
|
|
126
|
-
functions such as quotient,
|
|
127
|
-
remainder, exponentiation, and
|
|
128
|
-
modular exponentiation.
|
|
72
|
+
The eig function fixed
|
|
73
|
+
calculation errors and changed
|
|
74
|
+
its name to eigen
|
|
129
75
|
|
|
130
76
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
131
77
|
|
|
@@ -134,23 +80,13 @@ modular exponentiation.
|
|
|
134
80
|
<<<The ellipsis in the following structure represents the original part>>>
|
|
135
81
|
|
|
136
82
|
PyPyNum
|
|
137
|
-
★
|
|
138
|
-
CLASSES
|
|
139
|
-
BaseGraph
|
|
140
|
-
BaseWeGraph
|
|
141
|
-
WeDiGraph
|
|
142
|
-
WeUnGraph
|
|
143
|
-
DiGraph
|
|
144
|
-
UnGraph
|
|
145
|
-
★ polynomial [Polynomial object]
|
|
146
|
-
CLASSES
|
|
147
|
-
Polynomial
|
|
148
|
-
FUNCTIONS
|
|
149
|
-
poly(terms=None)
|
|
150
|
-
★ tools [Other useful tools]
|
|
83
|
+
★ Matrix [Matrix calculation]
|
|
151
84
|
FUNCTIONS
|
|
152
85
|
...
|
|
153
|
-
|
|
86
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
87
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
88
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
89
|
+
...
|
|
154
90
|
```
|
|
155
91
|
|
|
156
92
|
### 运行用时测试
|
|
@@ -265,14 +201,16 @@ PyPyNum
|
|
|
265
201
|
CLASSES
|
|
266
202
|
Matrix
|
|
267
203
|
FUNCTIONS
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
204
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
205
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
206
|
+
identity(n: int) -> pypynum.Matrix.Matrix
|
|
207
|
+
lu(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
271
208
|
mat(data)
|
|
272
|
-
qr(matrix)
|
|
209
|
+
qr(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
210
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
273
211
|
same(rows, cols, value=0)
|
|
274
|
-
svd(matrix)
|
|
275
|
-
tril_indices(n, k=0, m=None)
|
|
212
|
+
svd(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
213
|
+
tril_indices(n: int, k: int = 0, m: int = None) -> tuple
|
|
276
214
|
zeros(_dimensions)
|
|
277
215
|
zeros_like(_nested_list)
|
|
278
216
|
★ NeuralN [A simple neural network model]
|
|
@@ -456,6 +394,9 @@ PyPyNum
|
|
|
456
394
|
average(data, weights, expected=False)
|
|
457
395
|
exgcd(a: int, b: int) -> tuple
|
|
458
396
|
crt(n: arr, a: arr) -> int
|
|
397
|
+
isqrt(x: int) -> int
|
|
398
|
+
is_possibly_square(n: int) -> bool
|
|
399
|
+
is_square(n: int) -> bool
|
|
459
400
|
★ numbers [Conversion of various numbers]
|
|
460
401
|
FUNCTIONS
|
|
461
402
|
float2fraction(number: float, mixed: bool = False, error: float = 1e-15) -> tuple
|
|
@@ -685,7 +626,7 @@ print(v1.angles())
|
|
|
685
626
|
6.62607015e-34
|
|
686
627
|
1.618033988749895
|
|
687
628
|
3.141592653589793
|
|
688
|
-
1000000000000
|
|
629
|
+
1000000000000
|
|
689
630
|
|
|
690
631
|
>>> p = [1, -2, -3, 4]
|
|
691
632
|
>>> m = [
|
|
@@ -699,7 +640,9 @@ print(v1.angles())
|
|
|
699
640
|
>>> print(equations.polynomial_equation(p))
|
|
700
641
|
>>> print(equations.linear_equation(*m))
|
|
701
642
|
|
|
702
|
-
[(-1.5615528128088307-6.5209667308287455e-24j)
|
|
643
|
+
[[(-1.5615528128088307-6.5209667308287455e-24j) 0 0]
|
|
644
|
+
[ 0 (2.5615528128088294+4.456233626665941e-24j) 0]
|
|
645
|
+
[ 0 0 (1.0000000000000007+3.241554513744382e-25j)]]
|
|
703
646
|
[ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
|
|
704
647
|
|
|
705
648
|
>>> print(maths.cot(constants.pi / 3))
|
|
@@ -794,10 +737,10 @@ print(v1.angles())
|
|
|
794
737
|
>>> print(random.randint(0, 9, [2, 3, 4]))
|
|
795
738
|
>>> print(random.uniform(0, 9, [2, 3, 4]))
|
|
796
739
|
|
|
797
|
-
[[[
|
|
798
|
-
[[[0.
|
|
799
|
-
[[[
|
|
800
|
-
[[[
|
|
740
|
+
[[[1.524086835643172, -0.20868457467847845, 0.5240261503975477, -0.6439838767682032], [-1.091904210196648, -0.20567633973733265, 1.374424576574523, 0.6563097903476932], [0.2171635934136032, 1.0821030876490199, -0.8410496800310051, -0.8321549344577578]], [[0.5306996954571072, -0.4441704154154241, 1.0481960055260355, 0.39805451821848287], [-0.4006858882593715, -0.06238294764009237, -1.1536673264483728, -0.8063185246185602], [0.3029117113345387, -0.32570360518676644, 0.6608320231980702, 1.7415150171137153]]]
|
|
741
|
+
[[[0.3736243541521843, 0.8599079983285199, 0.4260061864869946, 0.8441437619796597], [0.8955986631978392, 0.7570336992646656, 0.6706841989644684, 0.328634366074538], [0.4371430562585502, 0.9576395263025738, 0.2380278778546957, 0.806813631306664]], [[0.18549375381453237, 0.5749941389233029, 0.7009767023241946, 0.30017399397762223], [0.6661914823434657, 0.7802291606608635, 0.6847755352217044, 0.2661053533652564], [0.07937643994416943, 0.5452043474222034, 0.8026792060861194, 0.07776400257578953]]]
|
|
742
|
+
[[[9, 0, 9, 0], [2, 6, 3, 4], [5, 8, 4, 7]], [[7, 7, 6, 3], [5, 5, 5, 8], [3, 4, 6, 6]]]
|
|
743
|
+
[[[5.049093842782947, 1.3880585421884204, 8.533634113864629, 3.550264239771317], [3.3311351975225176, 5.131771033264564, 0.9570872044431911, 5.165536082759862], [1.2035779060925538, 8.292998518472567, 8.014641974770818, 6.251632912237915]], [[6.411677800595937, 5.365937405245105, 8.70943859614565, 4.348757668525482], [7.827612569569748, 1.3718742546020972, 0.5252489627763138, 2.065015517785291], [4.620664668451086, 2.604569735623819, 5.548107842615733, 7.60342292447815]]]
|
|
801
744
|
|
|
802
745
|
>>> print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
803
746
|
>>> print(regression.parabolic_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -21,7 +21,7 @@ from .Graph import *
|
|
|
21
21
|
from .Group import group
|
|
22
22
|
from .Logic import *
|
|
23
23
|
from .maths import *
|
|
24
|
-
from .Matrix import mat, identity, lu, qr,
|
|
24
|
+
from .Matrix import mat, identity, rotate90, lu, qr, eigen, svd
|
|
25
25
|
from .NeuralN import *
|
|
26
26
|
from .numbers import *
|
|
27
27
|
from .plotting import unary, binary, c_unary, color
|
|
@@ -39,7 +39,7 @@ from . import types
|
|
|
39
39
|
from .utils import OrderedSet, InfIterator
|
|
40
40
|
from .Vector import vec
|
|
41
41
|
|
|
42
|
-
__version__ = "1.8.
|
|
42
|
+
__version__ = "1.8.1"
|
|
43
43
|
print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
|
|
44
44
|
"Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", sep=" | ")
|
|
45
45
|
del math, arr, ite, num, real, geom, ContentError, RandomError, LogicError, InputError, FullError, Union
|
|
@@ -10,8 +10,7 @@ def linear_equation(left: list, right: list) -> list:
|
|
|
10
10
|
|
|
11
11
|
def polynomial_equation(coefficients: list) -> list:
|
|
12
12
|
from .Array import array
|
|
13
|
-
from .Matrix import mat
|
|
14
|
-
from .__temporary import eigenvalue as eig
|
|
13
|
+
from .Matrix import eigen, mat
|
|
15
14
|
p = [_ / coefficients[0] for _ in coefficients[1:]]
|
|
16
|
-
return array(
|
|
17
|
-
for j in range(len(p))] for i in range(len(p))])))
|
|
15
|
+
return array(eigen(mat([[-p[i] if j == 0 else 1 if i + 1 == j else 0
|
|
16
|
+
for j in range(len(p))] for i in range(len(p))]))[0].data)
|
|
@@ -106,9 +106,14 @@ def lcm(*args: int) -> int:
|
|
|
106
106
|
"""
|
|
107
107
|
if not args:
|
|
108
108
|
return 0
|
|
109
|
+
try:
|
|
110
|
+
f = math.lcm
|
|
111
|
+
except AttributeError:
|
|
112
|
+
def f(a, b):
|
|
113
|
+
return a * b // math.gcd(a, b)
|
|
109
114
|
lcm_value = args[0]
|
|
110
115
|
for n in args[1:]:
|
|
111
|
-
lcm_value =
|
|
116
|
+
lcm_value = f(lcm_value, n)
|
|
112
117
|
return lcm_value
|
|
113
118
|
|
|
114
119
|
|
|
@@ -165,6 +165,7 @@ def c_unary(function, start: real, end: real, interval: real = 5, projection: st
|
|
|
165
165
|
:param coloration: bool.
|
|
166
166
|
:return:
|
|
167
167
|
"""
|
|
168
|
+
print("\n注意:自变量目前只支持实数范围\n\nNote: The independent variable currently only supports the real range\n")
|
|
168
169
|
if abs(interval) != interval:
|
|
169
170
|
raise ValueError("The interval cannot be less than zero")
|
|
170
171
|
if not isinstance(character, str) or (len(character) != 1 and not coloration):
|
|
@@ -4,22 +4,14 @@ with open("pypynum/README.md", "r", encoding="UTF-8") as r:
|
|
|
4
4
|
md = r.read()
|
|
5
5
|
|
|
6
6
|
keywords = [
|
|
7
|
-
"math", "数学", "mathematics", "数学计算",
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"tools", "工具", "utils", "实用程序",
|
|
16
|
-
"algorithms", "算法", "software", "软件",
|
|
17
|
-
"package", "包", "methods", "方法",
|
|
18
|
-
"data-science", "数据科学", "machine-learning", "机器学习",
|
|
19
|
-
"computational", "计算的", "operations", "操作",
|
|
20
|
-
"functions", "函数", "processing", "处理",
|
|
21
|
-
"programming", "编程", "simulation", "仿真",
|
|
22
|
-
"visualization", "可视化", "physics", "物理"
|
|
7
|
+
"math", "数学", "mathematics", "数学计算", "numerical", "数值", "computation", "计算",
|
|
8
|
+
"scientific", "科学", "algebra", "代数", "calculus", "微积分", "statistics", "统计",
|
|
9
|
+
"linear-algebra", "线性代数", "optimization", "优化", "numerical-analysis", "数值分析", "matrix", "矩阵",
|
|
10
|
+
"vector", "向量", "tensor", "张量", "numerics", "数值计算", "library", "库",
|
|
11
|
+
"tools", "工具", "utils", "实用程序", "algorithms", "算法", "software", "软件",
|
|
12
|
+
"package", "包", "methods", "方法", "data-science", "数据科学", "machine-learning", "机器学习",
|
|
13
|
+
"computational", "计算的", "operations", "操作", "functions", "函数", "processing", "处理",
|
|
14
|
+
"programming", "编程", "simulation", "仿真", "visualization", "可视化", "physics", "物理"
|
|
23
15
|
]
|
|
24
16
|
|
|
25
17
|
LICENSE = """
|
|
@@ -688,7 +680,7 @@ For more information on this, and how to apply and follow the GNU AGPL, see
|
|
|
688
680
|
|
|
689
681
|
setup(
|
|
690
682
|
name="PyPyNum",
|
|
691
|
-
version="1.8.
|
|
683
|
+
version="1.8.1",
|
|
692
684
|
packages=find_packages(),
|
|
693
685
|
url="https://www.gitee.com/PythonSJL/PyPyNum",
|
|
694
686
|
license=LICENSE,
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
def eigenvalue(matrix, eps=1e-100):
|
|
2
|
-
from math import hypot
|
|
3
|
-
from cmath import sqrt
|
|
4
|
-
from .Matrix import mat
|
|
5
|
-
A = matrix.copy()
|
|
6
|
-
n = A.rows
|
|
7
|
-
if n == 1:
|
|
8
|
-
return [A[0]], mat([[1]])
|
|
9
|
-
T = [0j] * n
|
|
10
|
-
if n > 2:
|
|
11
|
-
for i in range(n - 1, 1, -1):
|
|
12
|
-
scale = 0
|
|
13
|
-
for k in range(0, i):
|
|
14
|
-
scale += abs(A[i, k].real) + abs(A[i, k].imag)
|
|
15
|
-
scale_inv = 0
|
|
16
|
-
if scale != 0:
|
|
17
|
-
scale_inv = 1 / scale
|
|
18
|
-
if scale == 0 or scale_inv == float("inf"):
|
|
19
|
-
T[i] = 0
|
|
20
|
-
A[i, i - 1] = 0
|
|
21
|
-
continue
|
|
22
|
-
H = 0
|
|
23
|
-
for k in range(0, i):
|
|
24
|
-
A[i, k] = A[i, k] * scale_inv
|
|
25
|
-
rr, ii = A[i, k].real, A[i, k].imag
|
|
26
|
-
H += rr * rr + ii * ii
|
|
27
|
-
F = A[i, i - 1]
|
|
28
|
-
f = abs(F)
|
|
29
|
-
G = sqrt(H)
|
|
30
|
-
A[i, i - 1] = - G * scale
|
|
31
|
-
if f == 0:
|
|
32
|
-
T[i] = G
|
|
33
|
-
else:
|
|
34
|
-
ff = F / f
|
|
35
|
-
T[i] = F + G * ff
|
|
36
|
-
A[i, i - 1] = A[i, i - 1] * ff
|
|
37
|
-
H += G * f
|
|
38
|
-
H = 1 / sqrt(H)
|
|
39
|
-
T[i] *= H
|
|
40
|
-
for k in range(0, i - 1):
|
|
41
|
-
A[i, k] = A[i, k] * H
|
|
42
|
-
for j in range(0, i):
|
|
43
|
-
G = T[i].conjugate() * A[j, i - 1]
|
|
44
|
-
for k in range(0, i - 1):
|
|
45
|
-
G += A[i, k].conjugate() * A[j, k]
|
|
46
|
-
A[j, i - 1] = A[j, i - 1] - G * T[i]
|
|
47
|
-
for k in range(0, i - 1):
|
|
48
|
-
A[j, k] = A[j, k] - G * A[i, k]
|
|
49
|
-
for j in range(0, n):
|
|
50
|
-
G = T[i] * A[i - 1, j]
|
|
51
|
-
for k in range(0, i - 1):
|
|
52
|
-
G += A[i, k] * A[k, j]
|
|
53
|
-
A[i - 1, j] = A[i - 1, j] - G * T[i].conjugate()
|
|
54
|
-
for k in range(0, i - 1):
|
|
55
|
-
A[k, j] = A[k, j] - G * A[i, k].conjugate()
|
|
56
|
-
Q = A.copy()
|
|
57
|
-
for x in range(n):
|
|
58
|
-
for y in range(x + 2, n):
|
|
59
|
-
Q[y, x] = 0
|
|
60
|
-
norm = 0
|
|
61
|
-
for x in range(n):
|
|
62
|
-
for y in range(min(x + 2, n)):
|
|
63
|
-
norm += abs(Q[y, x])
|
|
64
|
-
norm = norm ** 0.5 / n
|
|
65
|
-
if norm == 0:
|
|
66
|
-
return
|
|
67
|
-
n0 = 0
|
|
68
|
-
n1 = n
|
|
69
|
-
eps0 = eps / (100 * n)
|
|
70
|
-
its = 0
|
|
71
|
-
while True:
|
|
72
|
-
k = n0
|
|
73
|
-
while k + 1 < n1:
|
|
74
|
-
s = abs(Q[k, k].real) + abs(Q[k, k].imag) + abs(Q[k + 1, k + 1].real) + abs(Q[k + 1, k + 1].imag)
|
|
75
|
-
if s < eps0 * norm:
|
|
76
|
-
s = norm
|
|
77
|
-
if abs(Q[k + 1, k]) < eps0 * s:
|
|
78
|
-
break
|
|
79
|
-
k += 1
|
|
80
|
-
if k + 1 < n1:
|
|
81
|
-
Q[k + 1, k] = 0
|
|
82
|
-
n0 = k + 1
|
|
83
|
-
its = 0
|
|
84
|
-
if n0 + 1 >= n1:
|
|
85
|
-
n0 = 0
|
|
86
|
-
n1 = k + 1
|
|
87
|
-
if n1 < 2:
|
|
88
|
-
break
|
|
89
|
-
else:
|
|
90
|
-
if its % 30 == 10:
|
|
91
|
-
shift = Q[n1 - 1, n1 - 2]
|
|
92
|
-
elif its % 30 == 20:
|
|
93
|
-
shift = abs(Q[n1 - 1, n1 - 2])
|
|
94
|
-
elif its % 30 == 29:
|
|
95
|
-
shift = norm
|
|
96
|
-
else:
|
|
97
|
-
t = Q[n1 - 2, n1 - 2] + Q[n1 - 1, n1 - 1]
|
|
98
|
-
s = (Q[n1 - 1, n1 - 1] - Q[n1 - 2, n1 - 2]) ** 2 + 4 * Q[n1 - 1, n1 - 2] * Q[n1 - 2, n1 - 1]
|
|
99
|
-
if s.real > 0:
|
|
100
|
-
s = sqrt(s)
|
|
101
|
-
else:
|
|
102
|
-
s = sqrt(-s) * 1j
|
|
103
|
-
a = (t + s) / 2
|
|
104
|
-
b = (t - s) / 2
|
|
105
|
-
if abs(Q[n1 - 1, n1 - 1] - a) > abs(Q[n1 - 1, n1 - 1] - b):
|
|
106
|
-
shift = b
|
|
107
|
-
else:
|
|
108
|
-
shift = a
|
|
109
|
-
its += 1
|
|
110
|
-
c = Q[n0, n0] - shift
|
|
111
|
-
s = Q[n0 + 1, n0]
|
|
112
|
-
v = hypot(abs(c), abs(s))
|
|
113
|
-
if v == 0:
|
|
114
|
-
c = 1
|
|
115
|
-
s = 0
|
|
116
|
-
else:
|
|
117
|
-
c /= v
|
|
118
|
-
s /= v
|
|
119
|
-
cc = c.conjugate()
|
|
120
|
-
cs = s.conjugate()
|
|
121
|
-
for k in range(n0, n):
|
|
122
|
-
x = Q[n0, k]
|
|
123
|
-
y = Q[n0 + 1, k]
|
|
124
|
-
Q[n0, k] = cc * x + cs * y
|
|
125
|
-
Q[n0 + 1, k] = c * y - s * x
|
|
126
|
-
for k in range(min(n1, n0 + 3)):
|
|
127
|
-
x = Q[k, n0]
|
|
128
|
-
y = Q[k, n0 + 1]
|
|
129
|
-
Q[k, n0] = c * x + s * y
|
|
130
|
-
Q[k, n0 + 1] = cc * y - cs * x
|
|
131
|
-
if not isinstance(A, bool):
|
|
132
|
-
for k in range(n):
|
|
133
|
-
x = A[k, n0]
|
|
134
|
-
y = A[k, n0 + 1]
|
|
135
|
-
A[k, n0] = c * x + s * y
|
|
136
|
-
A[k, n0 + 1] = cc * y - cs * x
|
|
137
|
-
for j in range(n0, n1 - 2):
|
|
138
|
-
c = Q[j + 1, j]
|
|
139
|
-
s = Q[j + 2, j]
|
|
140
|
-
v = hypot(abs(c), abs(s))
|
|
141
|
-
if v == 0:
|
|
142
|
-
Q[j + 1, j] = 0
|
|
143
|
-
c = 1
|
|
144
|
-
s = 0
|
|
145
|
-
else:
|
|
146
|
-
Q[j + 1, j] = v
|
|
147
|
-
c /= v
|
|
148
|
-
s /= v
|
|
149
|
-
Q[j + 2, j] = 0
|
|
150
|
-
cc = c.conjugate()
|
|
151
|
-
cs = s.conjugate()
|
|
152
|
-
for k in range(j + 1, n):
|
|
153
|
-
x = Q[j + 1, k]
|
|
154
|
-
y = Q[j + 2, k]
|
|
155
|
-
Q[j + 1, k] = cc * x + cs * y
|
|
156
|
-
Q[j + 2, k] = c * y - s * x
|
|
157
|
-
for k in range(0, min(n1, j + 4)):
|
|
158
|
-
x = Q[k, j + 1]
|
|
159
|
-
y = Q[k, j + 2]
|
|
160
|
-
Q[k, j + 1] = c * x + s * y
|
|
161
|
-
Q[k, j + 2] = cc * y - cs * x
|
|
162
|
-
if not isinstance(A, bool):
|
|
163
|
-
for k in range(0, n):
|
|
164
|
-
x = A[k, j + 1]
|
|
165
|
-
y = A[k, j + 2]
|
|
166
|
-
A[k, j + 1] = c * x + s * y
|
|
167
|
-
A[k, j + 2] = cc * y - cs * x
|
|
168
|
-
E = [Q[_, _] for _ in range(n)]
|
|
169
|
-
return E
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|