PyPyNum 1.8.0__py3-none-any.whl → 1.8.2__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.8.0.dist-info → PyPyNum-1.8.2.dist-info}/METADATA +59 -92
- {PyPyNum-1.8.0.dist-info → PyPyNum-1.8.2.dist-info}/RECORD +15 -16
- pypynum/Array.py +5 -2
- pypynum/Matrix.py +236 -32
- pypynum/Quaternion.py +1 -1
- pypynum/README.md +55 -88
- pypynum/Vector.py +2 -2
- pypynum/__init__.py +3 -3
- pypynum/equations.py +3 -4
- pypynum/maths.py +15 -10
- pypynum/plotting.py +1 -0
- pypynum/test.py +2 -1
- pypynum/this.py +2 -1
- pypynum/__temporary.py +0 -169
- {PyPyNum-1.8.0.dist-info → PyPyNum-1.8.2.dist-info}/WHEEL +0 -0
- {PyPyNum-1.8.0.dist-info → PyPyNum-1.8.2.dist-info}/top_level.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: PyPyNum
|
|
3
|
-
Version: 1.8.
|
|
4
|
-
Summary: A multifunctional mathematical calculation package written in pure Python programming language [Python>=3.
|
|
5
|
-
Home-page: https://
|
|
3
|
+
Version: 1.8.2
|
|
4
|
+
Summary: A multifunctional mathematical calculation package written in pure Python programming language [Python>=3.4]
|
|
5
|
+
Home-page: https://github.com/PythonSJL/PyPyNum
|
|
6
6
|
Author: Shen Jiayi
|
|
7
7
|
Author-email: 2261748025@qq.com
|
|
8
8
|
License:
|
|
@@ -669,13 +669,13 @@ License:
|
|
|
669
669
|
<http://www.gnu.org/licenses/>.
|
|
670
670
|
|
|
671
671
|
Keywords: math,数学,mathematics,数学计算,numerical,数值,computation,计算,scientific,科学,algebra,代数,calculus,微积分,statistics,统计,linear-algebra,线性代数,optimization,优化,numerical-analysis,数值分析,matrix,矩阵,vector,向量,tensor,张量,numerics,数值计算,library,库,tools,工具,utils,实用程序,algorithms,算法,software,软件,package,包,methods,方法,data-science,数据科学,machine-learning,机器学习,computational,计算的,operations,操作,functions,函数,processing,处理,programming,编程,simulation,仿真,visualization,可视化,physics,物理
|
|
672
|
-
Requires-Python: >=3.
|
|
672
|
+
Requires-Python: >=3.4
|
|
673
673
|
Description-Content-Type: text/markdown
|
|
674
674
|
|
|
675
675
|
# <font color = blue>PyPyNum</font>
|
|
676
676
|
|
|
677
677
|
<font color = gree>A multifunctional mathematical calculation package written in pure Python programming language
|
|
678
|
-
</font><font color = red>[Python>=3.
|
|
678
|
+
</font><font color = red>[Python>=3.4]</font>
|
|
679
679
|
|
|
680
680
|
```
|
|
681
681
|
________ ___ ___ ________ ___ ___ ________ ___ ___ _____ ______
|
|
@@ -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.2 | 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
|
|
|
@@ -704,8 +704,9 @@ The logo cannot be displayed on PyPI, it can be viewed in Gitee.
|
|
|
704
704
|
|
|
705
705
|
#### Introduction
|
|
706
706
|
|
|
707
|
-
+
|
|
708
|
-
+
|
|
707
|
+
+ 多功能数学库,类似于numpy、scipy等,专为PyPy解释器制作,亦支持其他类型的Python解释器
|
|
708
|
+
+ Multi functional math library, similar to numpy, scipy, etc., designed specifically for PyPy interpreters and also
|
|
709
|
+
supports other types of Python interpreters
|
|
709
710
|
+ 不定期更新版本,增加更多实用功能
|
|
710
711
|
+ Update versions periodically to add more practical features
|
|
711
712
|
+ 如需联系,QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
|
|
@@ -741,90 +742,49 @@ Python interpreter and run it!)
|
|
|
741
742
|
```
|
|
742
743
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
743
744
|
|
|
744
|
-
|
|
745
|
+
已确认此库能够向下兼容Python 3.4版本
|
|
746
|
+
以此支持IronPython解释器。
|
|
745
747
|
|
|
746
|
-
|
|
748
|
+
It has been confirmed that this
|
|
749
|
+
library is backward compatible
|
|
750
|
+
with Python version 3.4 to
|
|
751
|
+
support the IronPython
|
|
752
|
+
interpreter.
|
|
747
753
|
|
|
748
754
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
749
755
|
|
|
750
|
-
|
|
751
|
-
以生成任意大于等于三的整数阶幻方。
|
|
756
|
+
修改并优化了部分功能。
|
|
752
757
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
generate any integer order magic
|
|
756
|
-
square greater than or equal to
|
|
757
|
-
three.
|
|
758
|
+
Modified and optimized some
|
|
759
|
+
features.
|
|
758
760
|
|
|
759
761
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
760
762
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
first search for graph
|
|
777
|
-
traversal. It also has functions
|
|
778
|
-
such as calculating the shortest
|
|
779
|
-
path.
|
|
763
|
+
修改了fill函数,该函数将一维值序列填充
|
|
764
|
+
到指定形状的数组中。如果未指定列表,则默
|
|
765
|
+
认为从零开始递增的序列。此函数默认为循环
|
|
766
|
+
填充,否则使用零填充来填充剩余位置。
|
|
767
|
+
|
|
768
|
+
Modified the fill function,
|
|
769
|
+
which fills a one-dimensional
|
|
770
|
+
value sequence into an array of
|
|
771
|
+
specified shapes. If no list is
|
|
772
|
+
specified, it defaults to a
|
|
773
|
+
sequence that increments from
|
|
774
|
+
zero. This function defaults to
|
|
775
|
+
loop padding, otherwise zero
|
|
776
|
+
padding is used to fill the
|
|
777
|
+
remaining positions.
|
|
780
778
|
|
|
781
779
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
782
780
|
|
|
783
|
-
|
|
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.
|
|
781
|
+
使用辛普森公式提高定积分的计算精度。
|
|
803
782
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
<<<The ellipsis in the following structure represents the original part>>>
|
|
783
|
+
Use Simpson's formula to improve
|
|
784
|
+
the calculation accuracy of
|
|
785
|
+
definite integrals.
|
|
809
786
|
|
|
810
|
-
|
|
811
|
-
★ Graph [Graph theory]
|
|
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]
|
|
825
|
-
FUNCTIONS
|
|
826
|
-
...
|
|
827
|
-
magic_square(n)
|
|
787
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
828
788
|
```
|
|
829
789
|
|
|
830
790
|
### 运行用时测试
|
|
@@ -875,7 +835,7 @@ PyPyNum
|
|
|
875
835
|
Array
|
|
876
836
|
FUNCTIONS
|
|
877
837
|
array(data=None)
|
|
878
|
-
fill(shape, sequence=None)
|
|
838
|
+
fill(shape, sequence=None, repeat=True)
|
|
879
839
|
function(_array, _function, args=None)
|
|
880
840
|
get_shape(data)
|
|
881
841
|
is_valid_array(_array, _shape)
|
|
@@ -939,14 +899,16 @@ PyPyNum
|
|
|
939
899
|
CLASSES
|
|
940
900
|
Matrix
|
|
941
901
|
FUNCTIONS
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
902
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
903
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
904
|
+
identity(n: int) -> pypynum.Matrix.Matrix
|
|
905
|
+
lu(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
945
906
|
mat(data)
|
|
946
|
-
qr(matrix)
|
|
907
|
+
qr(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
908
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
947
909
|
same(rows, cols, value=0)
|
|
948
|
-
svd(matrix)
|
|
949
|
-
tril_indices(n, k=0, m=None)
|
|
910
|
+
svd(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
911
|
+
tril_indices(n: int, k: int = 0, m: int = None) -> tuple
|
|
950
912
|
zeros(_dimensions)
|
|
951
913
|
zeros_like(_nested_list)
|
|
952
914
|
★ NeuralN [A simple neural network model]
|
|
@@ -1130,6 +1092,9 @@ PyPyNum
|
|
|
1130
1092
|
average(data, weights, expected=False)
|
|
1131
1093
|
exgcd(a: int, b: int) -> tuple
|
|
1132
1094
|
crt(n: arr, a: arr) -> int
|
|
1095
|
+
isqrt(x: int) -> int
|
|
1096
|
+
is_possibly_square(n: int) -> bool
|
|
1097
|
+
is_square(n: int) -> bool
|
|
1133
1098
|
★ numbers [Conversion of various numbers]
|
|
1134
1099
|
FUNCTIONS
|
|
1135
1100
|
float2fraction(number: float, mixed: bool = False, error: float = 1e-15) -> tuple
|
|
@@ -1359,7 +1324,7 @@ print(v1.angles())
|
|
|
1359
1324
|
6.62607015e-34
|
|
1360
1325
|
1.618033988749895
|
|
1361
1326
|
3.141592653589793
|
|
1362
|
-
1000000000000
|
|
1327
|
+
1000000000000
|
|
1363
1328
|
|
|
1364
1329
|
>>> p = [1, -2, -3, 4]
|
|
1365
1330
|
>>> m = [
|
|
@@ -1373,7 +1338,9 @@ print(v1.angles())
|
|
|
1373
1338
|
>>> print(equations.polynomial_equation(p))
|
|
1374
1339
|
>>> print(equations.linear_equation(*m))
|
|
1375
1340
|
|
|
1376
|
-
[(-1.5615528128088307-6.5209667308287455e-24j)
|
|
1341
|
+
[[(-1.5615528128088307-6.5209667308287455e-24j) 0 0]
|
|
1342
|
+
[ 0 (2.5615528128088294+4.456233626665941e-24j) 0]
|
|
1343
|
+
[ 0 0 (1.0000000000000007+3.241554513744382e-25j)]]
|
|
1377
1344
|
[ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
|
|
1378
1345
|
|
|
1379
1346
|
>>> print(maths.cot(constants.pi / 3))
|
|
@@ -1468,10 +1435,10 @@ print(v1.angles())
|
|
|
1468
1435
|
>>> print(random.randint(0, 9, [2, 3, 4]))
|
|
1469
1436
|
>>> print(random.uniform(0, 9, [2, 3, 4]))
|
|
1470
1437
|
|
|
1471
|
-
[[[
|
|
1472
|
-
[[[0.
|
|
1473
|
-
[[[
|
|
1474
|
-
[[[
|
|
1438
|
+
[[[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]]]
|
|
1439
|
+
[[[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]]]
|
|
1440
|
+
[[[9, 0, 9, 0], [2, 6, 3, 4], [5, 8, 4, 7]], [[7, 7, 6, 3], [5, 5, 5, 8], [3, 4, 6, 6]]]
|
|
1441
|
+
[[[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
1442
|
|
|
1476
1443
|
>>> print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
1477
1444
|
>>> print(regression.parabolic_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
@@ -1,40 +1,39 @@
|
|
|
1
|
-
pypynum/Array.py,sha256=
|
|
1
|
+
pypynum/Array.py,sha256=U6_BzAazuz0XY6LAsRtxW9NS6vY-oF8Pk-N49_vQlgI,6739
|
|
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
|
|
5
5
|
pypynum/Group.py,sha256=m39OZNRoG9b3p_7sS1u50A0rJl0aYqYPVvnttkYQ_gw,2944
|
|
6
6
|
pypynum/Logic.py,sha256=IJAv59ECHU0HmG9lYCAQ_puqeL6Zor3-IDIVH48KBWE,11000
|
|
7
|
-
pypynum/Matrix.py,sha256=
|
|
7
|
+
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
|
-
pypynum/Quaternion.py,sha256
|
|
11
|
-
pypynum/README.md,sha256=
|
|
10
|
+
pypynum/Quaternion.py,sha256=-BW_crP_i-veHN0_pD3Z1dipFNUX198oZDrUYTsoZw0,8017
|
|
11
|
+
pypynum/README.md,sha256=0M7ZUC1Xi4duMsXQ61cwoUiVg5hBa_PiAsnaeuruZtE,43586
|
|
12
12
|
pypynum/Symbolics.py,sha256=Nfo0DEch7LII53ye1wZAdIfd3IAOKbECnZQMSk_cmCs,2898
|
|
13
13
|
pypynum/Tensor.py,sha256=SJzGRNwHZzOgEabt47scccb-plA25-6s01SFyHd6lJo,3801
|
|
14
14
|
pypynum/Tree.py,sha256=MUT9LErZ3ER_cbiga-nOaZC7Hln8jEV8tRca2dRPWmY,2827
|
|
15
|
-
pypynum/Vector.py,sha256=
|
|
16
|
-
pypynum/__init__.py,sha256=
|
|
17
|
-
pypynum/__temporary.py,sha256=OAs7it7xjDovgAmKLcj-9Pqp0228SSon3OZx0ih_h4I,5860
|
|
15
|
+
pypynum/Vector.py,sha256=0GSLDmUE0ZWB4JELB4rL6xHhf767wJlSIIdLt2ZpO9M,3526
|
|
16
|
+
pypynum/__init__.py,sha256=h801qsk1weSnt6yQ97HKc9aNpZpvDh9lpyfauhnpVQU,1905
|
|
18
17
|
pypynum/chars.py,sha256=VcK9w0i73FMCzc-9aIibjdHqyMsofJXdoBq0d8L7Vr0,1001
|
|
19
18
|
pypynum/cipher.py,sha256=J5PZl8Xt71LuX29eSBu4cybNK6Z3rhA9og_YzD0YJfU,1002
|
|
20
19
|
pypynum/constants.py,sha256=s2P1K8HH2nqoA6_YOVf6TKRl1Ozjf79GmCmLN9YbWxI,843
|
|
21
|
-
pypynum/equations.py,sha256=
|
|
20
|
+
pypynum/equations.py,sha256=Bn1_VjwMnnvzT0mHYI0eAARRqIHuc3IpOfYvzojTPx0,713
|
|
22
21
|
pypynum/errors.py,sha256=11-Au4aV8H5ExaDuMtu5iuGvpRaJP8gW7XbGNRmefSI,173
|
|
23
22
|
pypynum/file.py,sha256=rqrPdcX0NOEPM8s40-ymgPKsTn0HKABW-VEh1OtPnsk,3188
|
|
24
|
-
pypynum/maths.py,sha256=
|
|
23
|
+
pypynum/maths.py,sha256=EmhJA0lR5tPYB3qPiY04zBhO-qnF9-Vd-DbCGC8q9H0,26719
|
|
25
24
|
pypynum/numbers.py,sha256=WOxwwAN3yHakN4eHcVNn35qsfDcgw3UPSblv4woWyDE,6028
|
|
26
|
-
pypynum/plotting.py,sha256=
|
|
25
|
+
pypynum/plotting.py,sha256=xoaG6KVoKTu2Zax2FXk3_bHkiu5LguGi_siNi1FLE98,8463
|
|
27
26
|
pypynum/polynomial.py,sha256=psFukA31Ed4U7hZHcCGWCpYMi8tanTsZl-pUdklikfg,5998
|
|
28
27
|
pypynum/probability.py,sha256=kZLCfZb2q_y1CVbozSZj9xQ8Dw3il5WcAojX0jsNyXw,2130
|
|
29
28
|
pypynum/random.py,sha256=vfTtyH5yOSKJoSI_-NT_Tg8wC-ZXT0wt34f87oaSpJY,4610
|
|
30
29
|
pypynum/regression.py,sha256=D9J9lM23HiyY4eE8vHKaHoiwuvD1RYhkVNO0jQ4yml4,2118
|
|
31
30
|
pypynum/sequence.py,sha256=7NSZm_p_B00KFj5XZrtSm2FXhsowxs0qg_Q_P4pAA8o,7194
|
|
32
|
-
pypynum/test.py,sha256=
|
|
33
|
-
pypynum/this.py,sha256=
|
|
31
|
+
pypynum/test.py,sha256=exqz_CRCCakwgFi9NvUWGuFl8qUxTePLUP1C4WWbCc0,8461
|
|
32
|
+
pypynum/this.py,sha256=GORWMUN9HCx0pr2wR712nwZLj-OfQmZGvnIhmof57X0,2162
|
|
34
33
|
pypynum/tools.py,sha256=jqmzsRi2INRlnI4hb4IbpMKHlvEww3ZKO9y6DxrJUbA,12697
|
|
35
34
|
pypynum/types.py,sha256=CVWPZo_ACr_QGH5gAOhoG3jK35peiqipu3PH8ScEYHE,181
|
|
36
35
|
pypynum/utils.py,sha256=V1k-JFHLr_VGUVqwOeAVH9Ju7AHQVEoVgYA7M-dPsLw,9881
|
|
37
|
-
PyPyNum-1.8.
|
|
38
|
-
PyPyNum-1.8.
|
|
39
|
-
PyPyNum-1.8.
|
|
40
|
-
PyPyNum-1.8.
|
|
36
|
+
PyPyNum-1.8.2.dist-info/METADATA,sha256=inblOm7FFuZjEyxTtefkuJECcNAxC16l9MoNYtNS-PA,85030
|
|
37
|
+
PyPyNum-1.8.2.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
|
|
38
|
+
PyPyNum-1.8.2.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
|
|
39
|
+
PyPyNum-1.8.2.dist-info/RECORD,,
|
pypynum/Array.py
CHANGED
|
@@ -183,19 +183,22 @@ def zeros_like(_nested_list):
|
|
|
183
183
|
return 0
|
|
184
184
|
|
|
185
185
|
|
|
186
|
-
def fill(shape, sequence=None):
|
|
186
|
+
def fill(shape, sequence=None, repeat=True):
|
|
187
187
|
pointer = -1
|
|
188
188
|
length = 1
|
|
189
189
|
for item in shape:
|
|
190
190
|
length *= item
|
|
191
191
|
if sequence is None:
|
|
192
192
|
sequence = list(range(length))
|
|
193
|
+
total = len(sequence)
|
|
193
194
|
|
|
194
195
|
def inner(_shape):
|
|
195
196
|
nonlocal pointer
|
|
196
197
|
if len(_shape) == 0:
|
|
198
|
+
if pointer == total and not repeat:
|
|
199
|
+
return 0
|
|
197
200
|
pointer += 1
|
|
198
|
-
return sequence[pointer %
|
|
201
|
+
return sequence[pointer % total]
|
|
199
202
|
else:
|
|
200
203
|
_array = []
|
|
201
204
|
for i in range(_shape[0]):
|
pypynum/Matrix.py
CHANGED
|
@@ -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
|
pypynum/Quaternion.py
CHANGED
|
@@ -203,4 +203,4 @@ def change(data: Union[Quaternion, Matrix, Euler], to: str) -> Union[Quaternion,
|
|
|
203
203
|
roll = atan2(t3, t4)
|
|
204
204
|
return Euler(yaw, pitch, roll)
|
|
205
205
|
else:
|
|
206
|
-
raise TypeError("Data can only be Euler or Quaternion")
|
|
206
|
+
raise TypeError("Data can only be Euler or Matrix or Quaternion")
|
pypynum/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# <font color = blue>PyPyNum</font>
|
|
2
2
|
|
|
3
3
|
<font color = gree>A multifunctional mathematical calculation package written in pure Python programming language
|
|
4
|
-
</font><font color = red>[Python>=3.
|
|
4
|
+
</font><font color = red>[Python>=3.4]</font>
|
|
5
5
|
|
|
6
6
|
```
|
|
7
7
|
________ ___ ___ ________ ___ ___ ________ ___ ___ _____ ______
|
|
@@ -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.2 | 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
|
|
|
@@ -30,8 +30,9 @@ The logo cannot be displayed on PyPI, it can be viewed in Gitee.
|
|
|
30
30
|
|
|
31
31
|
#### Introduction
|
|
32
32
|
|
|
33
|
-
+
|
|
34
|
-
+
|
|
33
|
+
+ 多功能数学库,类似于numpy、scipy等,专为PyPy解释器制作,亦支持其他类型的Python解释器
|
|
34
|
+
+ Multi functional math library, similar to numpy, scipy, etc., designed specifically for PyPy interpreters and also
|
|
35
|
+
supports other types of Python interpreters
|
|
35
36
|
+ 不定期更新版本,增加更多实用功能
|
|
36
37
|
+ Update versions periodically to add more practical features
|
|
37
38
|
+ 如需联系,QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
|
|
@@ -67,90 +68,49 @@ Python interpreter and run it!)
|
|
|
67
68
|
```
|
|
68
69
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
69
70
|
|
|
70
|
-
|
|
71
|
+
已确认此库能够向下兼容Python 3.4版本
|
|
72
|
+
以此支持IronPython解释器。
|
|
71
73
|
|
|
72
|
-
|
|
74
|
+
It has been confirmed that this
|
|
75
|
+
library is backward compatible
|
|
76
|
+
with Python version 3.4 to
|
|
77
|
+
support the IronPython
|
|
78
|
+
interpreter.
|
|
73
79
|
|
|
74
80
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
75
81
|
|
|
76
|
-
|
|
77
|
-
以生成任意大于等于三的整数阶幻方。
|
|
82
|
+
修改并优化了部分功能。
|
|
78
83
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
generate any integer order magic
|
|
82
|
-
square greater than or equal to
|
|
83
|
-
three.
|
|
84
|
+
Modified and optimized some
|
|
85
|
+
features.
|
|
84
86
|
|
|
85
87
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
86
88
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
first search for graph
|
|
103
|
-
traversal. It also has functions
|
|
104
|
-
such as calculating the shortest
|
|
105
|
-
path.
|
|
89
|
+
修改了fill函数,该函数将一维值序列填充
|
|
90
|
+
到指定形状的数组中。如果未指定列表,则默
|
|
91
|
+
认为从零开始递增的序列。此函数默认为循环
|
|
92
|
+
填充,否则使用零填充来填充剩余位置。
|
|
93
|
+
|
|
94
|
+
Modified the fill function,
|
|
95
|
+
which fills a one-dimensional
|
|
96
|
+
value sequence into an array of
|
|
97
|
+
specified shapes. If no list is
|
|
98
|
+
specified, it defaults to a
|
|
99
|
+
sequence that increments from
|
|
100
|
+
zero. This function defaults to
|
|
101
|
+
loop padding, otherwise zero
|
|
102
|
+
padding is used to fill the
|
|
103
|
+
remaining positions.
|
|
106
104
|
|
|
107
105
|
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
108
106
|
|
|
109
|
-
|
|
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.
|
|
107
|
+
使用辛普森公式提高定积分的计算精度。
|
|
129
108
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
<<<The ellipsis in the following structure represents the original part>>>
|
|
109
|
+
Use Simpson's formula to improve
|
|
110
|
+
the calculation accuracy of
|
|
111
|
+
definite integrals.
|
|
135
112
|
|
|
136
|
-
|
|
137
|
-
★ Graph [Graph theory]
|
|
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]
|
|
151
|
-
FUNCTIONS
|
|
152
|
-
...
|
|
153
|
-
magic_square(n)
|
|
113
|
+
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
|
|
154
114
|
```
|
|
155
115
|
|
|
156
116
|
### 运行用时测试
|
|
@@ -201,7 +161,7 @@ PyPyNum
|
|
|
201
161
|
Array
|
|
202
162
|
FUNCTIONS
|
|
203
163
|
array(data=None)
|
|
204
|
-
fill(shape, sequence=None)
|
|
164
|
+
fill(shape, sequence=None, repeat=True)
|
|
205
165
|
function(_array, _function, args=None)
|
|
206
166
|
get_shape(data)
|
|
207
167
|
is_valid_array(_array, _shape)
|
|
@@ -265,14 +225,16 @@ PyPyNum
|
|
|
265
225
|
CLASSES
|
|
266
226
|
Matrix
|
|
267
227
|
FUNCTIONS
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
228
|
+
eigen(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
229
|
+
hessenberg(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
230
|
+
identity(n: int) -> pypynum.Matrix.Matrix
|
|
231
|
+
lu(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
271
232
|
mat(data)
|
|
272
|
-
qr(matrix)
|
|
233
|
+
qr(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
234
|
+
rotate90(matrix: pypynum.Matrix.Matrix, times: int) -> pypynum.Matrix.Matrix
|
|
273
235
|
same(rows, cols, value=0)
|
|
274
|
-
svd(matrix)
|
|
275
|
-
tril_indices(n, k=0, m=None)
|
|
236
|
+
svd(matrix: pypynum.Matrix.Matrix) -> tuple
|
|
237
|
+
tril_indices(n: int, k: int = 0, m: int = None) -> tuple
|
|
276
238
|
zeros(_dimensions)
|
|
277
239
|
zeros_like(_nested_list)
|
|
278
240
|
★ NeuralN [A simple neural network model]
|
|
@@ -456,6 +418,9 @@ PyPyNum
|
|
|
456
418
|
average(data, weights, expected=False)
|
|
457
419
|
exgcd(a: int, b: int) -> tuple
|
|
458
420
|
crt(n: arr, a: arr) -> int
|
|
421
|
+
isqrt(x: int) -> int
|
|
422
|
+
is_possibly_square(n: int) -> bool
|
|
423
|
+
is_square(n: int) -> bool
|
|
459
424
|
★ numbers [Conversion of various numbers]
|
|
460
425
|
FUNCTIONS
|
|
461
426
|
float2fraction(number: float, mixed: bool = False, error: float = 1e-15) -> tuple
|
|
@@ -685,7 +650,7 @@ print(v1.angles())
|
|
|
685
650
|
6.62607015e-34
|
|
686
651
|
1.618033988749895
|
|
687
652
|
3.141592653589793
|
|
688
|
-
1000000000000
|
|
653
|
+
1000000000000
|
|
689
654
|
|
|
690
655
|
>>> p = [1, -2, -3, 4]
|
|
691
656
|
>>> m = [
|
|
@@ -699,7 +664,9 @@ print(v1.angles())
|
|
|
699
664
|
>>> print(equations.polynomial_equation(p))
|
|
700
665
|
>>> print(equations.linear_equation(*m))
|
|
701
666
|
|
|
702
|
-
[(-1.5615528128088307-6.5209667308287455e-24j)
|
|
667
|
+
[[(-1.5615528128088307-6.5209667308287455e-24j) 0 0]
|
|
668
|
+
[ 0 (2.5615528128088294+4.456233626665941e-24j) 0]
|
|
669
|
+
[ 0 0 (1.0000000000000007+3.241554513744382e-25j)]]
|
|
703
670
|
[ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
|
|
704
671
|
|
|
705
672
|
>>> print(maths.cot(constants.pi / 3))
|
|
@@ -794,10 +761,10 @@ print(v1.angles())
|
|
|
794
761
|
>>> print(random.randint(0, 9, [2, 3, 4]))
|
|
795
762
|
>>> print(random.uniform(0, 9, [2, 3, 4]))
|
|
796
763
|
|
|
797
|
-
[[[
|
|
798
|
-
[[[0.
|
|
799
|
-
[[[
|
|
800
|
-
[[[
|
|
764
|
+
[[[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]]]
|
|
765
|
+
[[[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]]]
|
|
766
|
+
[[[9, 0, 9, 0], [2, 6, 3, 4], [5, 8, 4, 7]], [[7, 7, 6, 3], [5, 5, 5, 8], [3, 4, 6, 6]]]
|
|
767
|
+
[[[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
768
|
|
|
802
769
|
>>> print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
|
803
770
|
>>> print(regression.parabolic_regression(list(range(5)), [2, 4, 6, 7, 8]))
|
pypynum/Vector.py
CHANGED
|
@@ -45,7 +45,7 @@ class Vector(Array):
|
|
|
45
45
|
return self.norm()
|
|
46
46
|
|
|
47
47
|
def __pos__(self):
|
|
48
|
-
return Vector([
|
|
48
|
+
return Vector([item for item in self.data])
|
|
49
49
|
|
|
50
50
|
def __neg__(self):
|
|
51
51
|
return Vector([-item for item in self.data])
|
|
@@ -73,7 +73,7 @@ class Vector(Array):
|
|
|
73
73
|
for a in range(self.len):
|
|
74
74
|
axis = Vector([1 if p == a else 0 for p in range(self.len)])
|
|
75
75
|
result.append(acos(self @ axis / (self.norm() * axis.norm())))
|
|
76
|
-
elif
|
|
76
|
+
elif int(abs(axes)) == axes:
|
|
77
77
|
axis = Vector([1 if p == axes else 0 for p in range(self.len)])
|
|
78
78
|
result = acos(self @ axis / (self.norm() * axis.norm()))
|
|
79
79
|
elif isinstance(axes, (list, tuple)):
|
pypynum/__init__.py
CHANGED
|
@@ -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, hessenberg, 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.2"
|
|
43
43
|
print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
|
|
44
|
-
"Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", sep=" | ")
|
|
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/equations.py
CHANGED
|
@@ -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)
|
pypynum/maths.py
CHANGED
|
@@ -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
|
|
|
@@ -745,7 +750,7 @@ def pi(i: int, n: int, f) -> num:
|
|
|
745
750
|
return product(list(map(f, range(i, n + 1))))
|
|
746
751
|
|
|
747
752
|
|
|
748
|
-
def derivative(f, x: real, h: real = 1e-
|
|
753
|
+
def derivative(f, x: real, h: real = 1e-6) -> float:
|
|
749
754
|
"""
|
|
750
755
|
introduction
|
|
751
756
|
==========
|
|
@@ -754,17 +759,18 @@ def derivative(f, x: real, h: real = 1e-7) -> float:
|
|
|
754
759
|
example
|
|
755
760
|
==========
|
|
756
761
|
>>> derivative(lambda a: a ** 2, 2)
|
|
757
|
-
|
|
762
|
+
4.000000000115023
|
|
758
763
|
>>>
|
|
759
764
|
:param f: function
|
|
760
765
|
:param x: integer | float
|
|
761
766
|
:param h: integer | float
|
|
762
767
|
:return:
|
|
763
768
|
"""
|
|
769
|
+
h = h / 2
|
|
764
770
|
return (f(x + h) - f(x - h)) / (2 * h)
|
|
765
771
|
|
|
766
772
|
|
|
767
|
-
def definite_integral(f, x_start: real, x_end: real, n: int =
|
|
773
|
+
def definite_integral(f, x_start: real, x_end: real, n: int = 1000000) -> float:
|
|
768
774
|
"""
|
|
769
775
|
introduction
|
|
770
776
|
==========
|
|
@@ -773,7 +779,7 @@ def definite_integral(f, x_start: real, x_end: real, n: int = 10000000) -> float
|
|
|
773
779
|
example
|
|
774
780
|
==========
|
|
775
781
|
>>> definite_integral(lambda a: a ** 2, 0, 2)
|
|
776
|
-
2.
|
|
782
|
+
2.666666666666616
|
|
777
783
|
>>>
|
|
778
784
|
:param f: function
|
|
779
785
|
:param x_start: integer | float
|
|
@@ -782,11 +788,10 @@ def definite_integral(f, x_start: real, x_end: real, n: int = 10000000) -> float
|
|
|
782
788
|
:return:
|
|
783
789
|
"""
|
|
784
790
|
h = (x_end - x_start) / n
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
return _sum * h / 2
|
|
791
|
+
s = f(x_start) + f(x_end)
|
|
792
|
+
s += sum(map(lambda i: 4 * f(x_start + i * h), range(1, n, 2)))
|
|
793
|
+
s += sum(map(lambda i: 2 * f(x_start + i * h), range(2, n - 1, 2)))
|
|
794
|
+
return s * h / 3
|
|
790
795
|
|
|
791
796
|
|
|
792
797
|
def beta(p: real, q: real) -> real:
|
pypynum/plotting.py
CHANGED
|
@@ -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):
|
pypynum/test.py
CHANGED
pypynum/this.py
CHANGED
|
@@ -5,5 +5,6 @@ The Zen of PyPyNum
|
|
|
5
5
|
Zen = "\x9a¤¢\xa0¢°¼§¢°éâñåâòõÖ°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\x9a\x9a±äù°õóñâòýõ°ã·äõü½äàõóþÿó°äåÿôþñäã°ñ°ãù°þ÷ùãõô°âñüåôÿÝ\x9a¾÷þùãùýÿâà°õò°äø÷ùý°äù°¼ôâñçâÿöäø÷ùñâäã°ãù°þÿùäñäþõýõüàýù°õøä°öÙ\x9a¾äù°âõôùãþÿóõâ°¼ôþõøõâàýÿó°ÿä°÷þù÷þõüüñøó°ãù°þÿùäñäþõýõüàýù°õøä°öÙ\x9a¾÷þùøãåâ°ÿä°âÿùâõàåã°ãù°÷þùäùñç°ãõýùäõýÿã°¼âõæõçÿØ\x9a¾þÿùäñþùäãñâóÿâà°þñøä°âõääõò°ãù°éüäàýÿâà°÷þùäóÑ\x9a¾øóñÿâààñ°ãåÿùæòÿ½õþÿ°éüþÿ°õøä°¼éüüñõôù½õþÿ°õò°äãåý°õâõøÄ\x9a¾õäñüåóõàã°ÿä°õ÷âå°õøä°äãùãõâ°¼ããõþõå÷ñæ°öÿ°õóþõãõâà°õøä°þÙ\x9a¾ôõäåý°éüäùóùüàèõ°ããõüþÅ\x9a¾ôõóþõüùã°äÿþ°¼þõûÿàã°õò°äãåý°ãâÿââÕ\x9a¾éäùâåà°âõæÿ°ãøàýåùâä°þõäöÿ°éäùüñóùäóñâÀ\x9a¾ãýâÿþ°õøä°õôùââõæÿ°äÿþ°ôüåÿøã°ãõãñó°üñùóõàÃ\x9a¾äþåÿýñâñà°ãù°éäùüùòñôñõÂ\x9a¾ãõþÿ°ôõäñÿüò°âõæÿ°ãþùç°õôÿó°õãâñàÃ\x9a¾ãõùøóâñâõùø°ôõäãõþ°ãäñõò°õâåäóåâäã°äñüÖ\x9a¾ôõäñóùüàýÿóâõæÿ°þñøä°âõääõò°ãù°ôõäñóùäãùøàÿÃ\x9a¾þÿùäåüÿæþÿó°âõæÿ°ôõââõöõâà°ãù°ããõþôâñçâÿöäø÷ùñâäÃ\x9a¾éäùâåóãòÿ°ãàýåâä°éäùâñüÓ\x9a¾éûþåüó°ÿä°âÿùâõàåã°ãù°äþñ÷õüÕ\x9a\x9a¾þÿøäéÀ°þù°éüõâåà°þõääùâç°õ÷ñûóñà°øäñý°ñ°ãù°ãùøÄ\x9a\x9aùéñùÚ°þõøÃ°éò°¼ýåÞéÀéÀ°öÿ°þõʰõøÄ°°°°\x9a"
|
|
6
6
|
print("".join([chr(ord(_) ^ 144) for _ in Zen[::-1]]))
|
|
7
7
|
for _ in list(globals().keys()):
|
|
8
|
-
|
|
8
|
+
if _ != "__builtins__":
|
|
9
|
+
del globals()[_]
|
|
9
10
|
del _
|
pypynum/__temporary.py
DELETED
|
@@ -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
|