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.
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPyNum
3
- Version: 1.8.0
4
- Summary: A multifunctional mathematical calculation package written in pure Python programming language [Python>=3.5]
5
- Home-page: https://www.gitee.com/PythonSJL/PyPyNum
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.5
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.5]</font>
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
  [![Downloads](https://static.pepy.tech/badge/pypynum/month)](https://pepy.tech/project/pypynum)
693
693
  [![Downloads](https://static.pepy.tech/badge/pypynum/week)](https://pepy.tech/project/pypynum)
694
694
 
695
- ## Version -> 1.8.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
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
  ![LOGO](PyPyNum.png)
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
- + DIY数学库,类似于numpy、scipy等,专为PyPy解释器制作
708
- + DIY math library, similar to numpy, scipy, etc., specifically designed for PyPy interpreters
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
- 新增代码行数为603行
745
+ 已确认此库能够向下兼容Python 3.4版本
746
+ 以此支持IronPython解释器。
745
747
 
746
- Add 603 new lines of code
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
- 新增函数“magic_square”的功能简介:可
751
- 以生成任意大于等于三的整数阶幻方。
756
+ 修改并优化了部分功能。
752
757
 
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
+ Modified and optimized some
759
+ features.
758
760
 
759
761
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
760
762
 
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.
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
- 新增模块“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.
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
- PyPyNum
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
- eig(matrix)
943
- identity(n)
944
- lu(matrix)
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.0
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) (2.5615528128088294+4.456233626665941e-24j) (1.0000000000000007+3.241554513744382e-25j)]
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
- [[[0.4334341920363395, 0.055711784711422116, -1.0235500373980284, 0.30031229336738374], [-0.2650367914670356, 0.5513398538865067, -0.9735921328831166, 0.41345578602104827], [-0.11598957920080871, -0.9044539791933183, 1.6448227575237069, -0.26304156924843813]], [[0.27363898507271256, -0.5897181011789576, 1.5120937498473583, 2.1302709742844694], [1.9743293887616236, 0.4117207260898469, 0.5809554193110543, -1.8456249006764007], [1.274481044612177, -0.30645083457981553, -1.3285606156236818, 0.33473439037886943]]]
1472
- [[[0.5269441534226782, 0.36498666932667356, 0.7363066388832684, 0.5878544826035406], [0.5684721009896431, 0.9009577979323332, 0.036288112799501615, 0.18351641818419884], [0.24258369409385339, 0.09354340906140202, 0.4856203412285762, 0.783031677244552]], [[0.8777465681935882, 0.6406910705155251, 0.10275292827025073, 0.01295823682977526], [0.3898500974345528, 0.6216248983423127, 0.3179425906177036, 0.012870877167621808], [0.2660481991211192, 0.09872041627158801, 0.3681944568198672, 0.494087114885137]]]
1473
- [[[5, 9, 5, 6], [6, 7, 6, 1], [1, 3, 2, 4]], [[5, 8, 8, 3], [3, 2, 3, 9], [3, 0, 7, 1]]]
1474
- [[[8.610851610963957, 1.3747433091161905, 1.3831050577679438, 4.715182178697273], [0.8765517657148284, 4.809554825684029, 2.7557819856736137, 5.938765584746821], [6.088739464744903, 4.627722536295625, 0.6116370455995369, 5.875683438664389]], [[7.7228845997304845, 5.428461366109726, 8.02712172516869, 5.9319006090345425], [5.726626482636939, 7.978329508380601, 1.114307478513796, 6.236721706167868], [1.4123245528031072, 5.327811122183013, 7.324213082306745, 1.5016363011868927]]]
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=MLGvkYC9V7fGAR3g1Xykt_-hJYDC8mE47ji8dBcqFhk,6632
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=Z2k0bl_VpnaWB3QZjokR9CR7-kDaYIKUjKITWTYGa98,11024
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=E7ajc4sDJyOuQQIwKPhUEHgiaeeR5BEzFZHhJMxvbok,8007
11
- pypynum/README.md,sha256=fiCTdsbI9rza9ZogDQ2jwxHhTFXD7dR6vfAbBTkYUP4,43971
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=eiFCY6H35pMvvDX7NpLux_bSfLI8rK8JHkaRxv7pOW8,3552
16
- pypynum/__init__.py,sha256=akxx-NuZTFE9fnNW9u6KUo3KyA-vU8iU_m70FQmfzb0,1831
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=_4xIXr7A56qBXKzJXyb91L4h09H7TDVNrcufy-XxkaI,744
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=53TDBkZkHh1FZIQFfhi-_YwXvTSf630G-ooDS1Z7PFc,26518
23
+ pypynum/maths.py,sha256=EmhJA0lR5tPYB3qPiY04zBhO-qnF9-Vd-DbCGC8q9H0,26719
25
24
  pypynum/numbers.py,sha256=WOxwwAN3yHakN4eHcVNn35qsfDcgw3UPSblv4woWyDE,6028
26
- pypynum/plotting.py,sha256=YQg9sO_nuLSaAKQuSpebWVvbu-ns2A7JOrHch6r0FQ0,8326
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=Bksa7HZaywKBbLaCw2R5kGRFj6eKzkkJ7BdJBgIB3uM,8428
33
- pypynum/this.py,sha256=8Swp75xE5g6436NCVDfYUVwUzUcQFPLcCNFWQWY5eGQ,2129
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.0.dist-info/METADATA,sha256=sKDkUYxVw125A9ZsbFD_AigRGifQOSUMR0jrIgKkIh8,85418
38
- PyPyNum-1.8.0.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
39
- PyPyNum-1.8.0.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
40
- PyPyNum-1.8.0.dist-info/RECORD,,
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 % len(sequence)]
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 lu(matrix):
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.data[b][a]) for a in range(cols)] for b in range(rows)]
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 eig(matrix):
277
- try:
278
- from numpy.linalg import eig as eigen
279
- e, Q = eigen(matrix.data)
280
- e, Q = Matrix([e.tolist()]), Matrix(Q.tolist())
281
- return e, Q
282
- except ImportError:
283
- eigen = "\n\033[91m提示:Matrix模块的eig函数可能存在计算错误\n\nTip: The eig function of the Matrix module may have calculation errors\033[m\n"
284
- print(eigen)
285
- _qr = []
286
- n = matrix.rows
287
- Q = identity(n)
288
- for i in range(100):
289
- _qr = qr(matrix)
290
- Q = Q @ _qr[0]
291
- matrix = _qr[1] @ _qr[0]
292
- AK = (_qr[0] @ _qr[1]).data
293
- e = Matrix([[AK[i][i] for i in range(n)]])
294
- return e, Q
295
-
296
-
297
- def svd(matrix):
298
- e0, U = eig(matrix @ matrix.t())
299
- e1, V = eig(matrix.t() @ matrix)
300
- sigma = Matrix([[((e0.data[0][a] + e1.data[0][a]) / 2) ** 0.5 if a == b else 0 for a in range(matrix.cols)]
301
- for b in range(matrix.rows)])
302
- return U, sigma, V.t()
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.5]</font>
4
+ </font><font color = red>[Python>=3.4]</font>
5
5
 
6
6
  ```
7
7
  ________ ___ ___ ________ ___ ___ ________ ___ ___ _____ ______
@@ -18,7 +18,7 @@
18
18
  [![Downloads](https://static.pepy.tech/badge/pypynum/month)](https://pepy.tech/project/pypynum)
19
19
  [![Downloads](https://static.pepy.tech/badge/pypynum/week)](https://pepy.tech/project/pypynum)
20
20
 
21
- ## Version -> 1.8.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
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
  ![LOGO](PyPyNum.png)
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
- + DIY数学库,类似于numpy、scipy等,专为PyPy解释器制作
34
- + DIY math library, similar to numpy, scipy, etc., specifically designed for PyPy interpreters
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
- 新增代码行数为603行
71
+ 已确认此库能够向下兼容Python 3.4版本
72
+ 以此支持IronPython解释器。
71
73
 
72
- Add 603 new lines of code
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
- 新增函数“magic_square”的功能简介:可
77
- 以生成任意大于等于三的整数阶幻方。
82
+ 修改并优化了部分功能。
78
83
 
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
+ Modified and optimized some
85
+ features.
84
86
 
85
87
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
86
88
 
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.
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
- 新增模块“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.
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
- PyPyNum
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
- eig(matrix)
269
- identity(n)
270
- lu(matrix)
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.0
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) (2.5615528128088294+4.456233626665941e-24j) (1.0000000000000007+3.241554513744382e-25j)]
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
- [[[0.4334341920363395, 0.055711784711422116, -1.0235500373980284, 0.30031229336738374], [-0.2650367914670356, 0.5513398538865067, -0.9735921328831166, 0.41345578602104827], [-0.11598957920080871, -0.9044539791933183, 1.6448227575237069, -0.26304156924843813]], [[0.27363898507271256, -0.5897181011789576, 1.5120937498473583, 2.1302709742844694], [1.9743293887616236, 0.4117207260898469, 0.5809554193110543, -1.8456249006764007], [1.274481044612177, -0.30645083457981553, -1.3285606156236818, 0.33473439037886943]]]
798
- [[[0.5269441534226782, 0.36498666932667356, 0.7363066388832684, 0.5878544826035406], [0.5684721009896431, 0.9009577979323332, 0.036288112799501615, 0.18351641818419884], [0.24258369409385339, 0.09354340906140202, 0.4856203412285762, 0.783031677244552]], [[0.8777465681935882, 0.6406910705155251, 0.10275292827025073, 0.01295823682977526], [0.3898500974345528, 0.6216248983423127, 0.3179425906177036, 0.012870877167621808], [0.2660481991211192, 0.09872041627158801, 0.3681944568198672, 0.494087114885137]]]
799
- [[[5, 9, 5, 6], [6, 7, 6, 1], [1, 3, 2, 4]], [[5, 8, 8, 3], [3, 2, 3, 9], [3, 0, 7, 1]]]
800
- [[[8.610851610963957, 1.3747433091161905, 1.3831050577679438, 4.715182178697273], [0.8765517657148284, 4.809554825684029, 2.7557819856736137, 5.938765584746821], [6.088739464744903, 4.627722536295625, 0.6116370455995369, 5.875683438664389]], [[7.7228845997304845, 5.428461366109726, 8.02712172516869, 5.9319006090345425], [5.726626482636939, 7.978329508380601, 1.114307478513796, 6.236721706167868], [1.4123245528031072, 5.327811122183013, 7.324213082306745, 1.5016363011868927]]]
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([abs(item) for item in self.data])
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 isinstance(axes, int) and abs(axes) == axes:
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, eig, svd
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.0"
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(eig(mat([[-p[i] if j == 0 else 1 if i + 1 == j else 0
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 = math.lcm(lcm_value, n)
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-7) -> float:
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
- 3.9999999956741306
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 = 10000000) -> float:
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.6666666666664036
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
- _sum = 0
786
- for i in range(n):
787
- x = x_start + i * h
788
- _sum += f(x + h) + f(x)
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
@@ -271,7 +271,8 @@ print(tools.frange(0, 3, 0.4))
271
271
  print(tools.linspace(0, 2.8, 8))
272
272
 
273
273
  for _ in list(globals().keys()):
274
- del globals()[_]
274
+ if _ != "__builtins__":
275
+ del globals()[_]
275
276
  del _
276
277
 
277
278
  print("""\033[91m
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
- del globals()[_]
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