PyPyNum 1.13.0__py3-none-any.whl → 1.13.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyPyNum
3
- Version: 1.13.0
3
+ Version: 1.13.1
4
4
  Summary: PyPyNum is a Python library for math & science computations, covering algebra, calculus, stats, with data structures like matrices, vectors, tensors. It offers numerical tools, programs, and supports computational ops, functions, processing, simulation, & visualization in data science & ML, crucial for research, engineering, & data processing.
5
5
  Home-page: https://github.com/PythonSJL/PyPyNum
6
6
  Author: Shen Jiayi
@@ -234,7 +234,7 @@ processing.</font><font color = red>[Python>=3.4]</font>
234
234
  [![Downloads](https://static.pepy.tech/badge/pypynum/month)](https://pepy.tech/project/pypynum)
235
235
  [![Downloads](https://static.pepy.tech/badge/pypynum/week)](https://pepy.tech/project/pypynum)
236
236
 
237
- ## Version -> 1.13.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
237
+ ## Version -> 1.13.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
238
238
 
239
239
  ![LOGO](PyPyNum.png)
240
240
 
@@ -339,102 +339,48 @@ Python interpreter and run it!
339
339
  ```
340
340
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
341
341
 
342
- multiprec模块新增了一些函数
342
+ 修正了MPComplex的错误并且新增了部分用
343
+ 于计算三角函数的方法
343
344
 
344
- The multiprec module has added some new functions
345
+ Corrected errors in MPComplex
346
+ and added some methods for
347
+ calculating trigonometric
348
+ functions
345
349
 
346
- asmpc(real: Union[int, float, str, decimal.Decimal, complex, pypynum.multiprec.MPComplex], imag: Union[int, float, str, decimal.Decimal] = 0, sigfigs: int = 28) -> pypynum.multiprec.MPComplex
347
- mp_acos(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
348
- mp_asin(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
349
- mp_fresnel_c(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
350
- mp_fresnel_s(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
350
+ !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
351
351
 
352
+ 增加了levenshtein_distance函数
352
353
 
353
- 新增了MPComplex类,
354
- 其实现了多精度复数计算,
355
- 目前支持加、减、乘、除、指数、对数等运算,
356
- 并且将在后面的版本增加各种三角函数。
354
+ Added levenshtein_distance function
357
355
 
358
- The MPComplex class has been added,
359
- which implements multi precision complex calculations.
360
- Currently,
361
- it supports operations such as addition,
362
- subtraction,
363
- multiplication,
364
- division,
365
- exponentiation,
366
- and logarithm,
367
- and various trigonometric functions will be added in later versions.
368
356
 
369
- MPComplex(real, imag, sigfigs=28)
357
+ Help on function levenshtein_distance in module pypynum.tools:
370
358
 
359
+ levenshtein_distance(s1: str, s2: str) -> int
360
+ Introduction
361
+ ==========
362
+ Calculate the Levenshtein distance between two strings.
371
363
 
372
- 创建多精度复数时建议使用asmpc函数,
373
- 因为它可以更方便地把其他数值类型转换为MPComplex对象。
364
+ The Levenshtein distance is a measure of the difference between two strings. It is defined as the minimum number
365
+ of single-character edits (i.e., insertions, deletions or substitutions) required to change one string into the
366
+ other.
374
367
 
375
- It is recommended to use the asmpc function when creating multi precision complex numbers,
376
- as it can more easily convert other numerical types to MPComplex objects.
368
+ Example
369
+ ==========
370
+ >>> levenshtein_distance("kitten", "sitting")
371
+ 3
372
+ >>>
373
+ :param s1: First string to compare.
374
+ :param s2: Second string to compare.
375
+ :return: The Levenshtein distance between the two strings.
377
376
 
378
377
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
379
378
 
380
- 移除了pypynum.tools.interp函数,改名为interp1d,
381
- 与新增的interp2d函数置于新的子模块——pypynum.interp。
382
-
383
- Removed the pypynum.tools.interp function and renamed it interp1d,
384
- placing it in a new submodule - pypynum.interp - along with the newly added interp2d function.
385
-
386
-
387
- Help on module pypynum.interp in pypynum:
388
-
389
- NAME
390
- pypynum.interp
391
-
392
- FUNCTIONS
393
- bicubic(x)
394
- Calculate the cubic B-spline interpolation function value.
395
- :param x: The x value for which the B-spline function is evaluated.
396
- :return: The value of the cubic B-spline function at x.
397
-
398
- contribute(src, x, y, channels=None)
399
- Calculate the contribution of the source array at a specific point after bicubic interpolation.
400
- :param src: The source 2D array from which to interpolate.
401
- :param x: The x-coordinate of the point to interpolate.
402
- :param y: The y-coordinate of the point to interpolate.
403
- :param channels: The number of channels if src is a multichannel array.
404
- :return: The interpolated value at the point (x, y).
405
-
406
- interp1d(data: Union[list, tuple], length: int) -> list
407
- Introduction
408
- ==========
409
- One-dimensional data interpolation
410
-
411
- Example
412
- ==========
413
- >>> interp1d((2, 4, 4, 2), 6)
414
- [2, 3.320000000000001, 4.160000000000005, 4.160000000000012, 3.3200000000000074, 2]
415
- >>>
416
- :param data: List of data points to be interpolated. Must be at least two points.
417
- :param length: The number of points in the resampled data set.
418
- :return: A list of interpolated values at the new points.
419
-
420
- interp2d(src, new_height, new_width, channels=None, round_res=False, min_val=None, max_val=None)
421
- Introduction
422
- ==========
423
- Two-dimensional data interpolation using bicubic spline interpolation.
424
-
425
- Example
426
- ==========
427
- >>> interp2d([[1, 2], [3, 4]], 3, 3)
428
- [[1.0, 1.6875, 2.0], [2.25, 3.1640625, 3.375], [3.0, 3.9375, 4.0]]
429
- >>>
430
- :param src: The source 2D array to be interpolated.
431
- :param new_height: The desired height of the interpolated array.
432
- :param new_width: The desired width of the interpolated array.
433
- :param channels: The number of channels if src is a multichannel array.
434
- :param round_res: Whether to round the result to the nearest integer.
435
- :param min_val: The minimum value to clip the interpolated results.
436
- :param max_val: The maximum value to clip the interpolated results.
437
- :return: A 2D array of the interpolated values with the new dimensions.
379
+ 注意:以后的版本中的自述文件将更改为纯英文
380
+
381
+ Attention: The self description
382
+ file in future versions will be
383
+ changed to pure English
438
384
 
439
385
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
440
386
  ```
@@ -876,6 +822,7 @@ PyPyNum
876
822
  │ ├── generate_primes(limit: int) -> list
877
823
  │ ├── generate_semiprimes(limit: int) -> list
878
824
  │ ├── geomspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
825
+ │ ├── levenshtein_distance(s1: str, s2: str) -> int
879
826
  │ ├── linspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
880
827
  │ ├── magic_square(n: Any) -> Any
881
828
  │ ├── primality(n: int, iter_num: int) -> bool
@@ -1256,8 +1203,8 @@ print(equations.poly_eq(p))
1256
1203
  print(equations.lin_eq(*m))
1257
1204
 
1258
1205
  """
1259
- [(-1.5615528128088307-6.5209667308287455e-24j) (1.0000000000000007+3.241554513744382e-25j) (2.5615528128088294+4.456233626665941e-24j)]
1260
- [ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
1206
+ [(-1.5615528128088307-6.5209667308287455e-24j), (1.0000000000000007+3.241554513744382e-25j), (2.5615528128088294+4.456233626665941e-24j)]
1207
+ [1.6666666666666665, -0.6666666666666666, -0.4444444444444444]
1261
1208
  """
1262
1209
 
1263
1210
  print(maths.cot(constants.pi / 3))
@@ -1357,10 +1304,10 @@ print(random.randint(0, 9, [2, 3, 4]))
1357
1304
  print(random.uniform(0, 9, [2, 3, 4]))
1358
1305
 
1359
1306
  """
1360
- [[[1.0022026821190488, -0.38242004448759154, -0.23648445523561967, 0.43813038741951754], [-0.3778652198785619, -0.03865603124657112, -1.5186239424691736, -0.7368762975012327], [-0.7580654190380791, -1.3672869759158346, 0.582588816791107, 1.0281649895276377]], [[0.5270622699930536, 0.6132250709048543, 0.9764619731696673, -0.13740454362420268], [-2.0801461607759886, -0.1935521020633617, 0.44420106801354153, 1.4830089202063659], [-0.8790685594194517, 0.45517163054358967, -1.1448643981658326, 0.986414969442009]]]
1361
- [[[0.13698864758140294, 0.634190467772759, 0.25683276170297875, 0.9026812741081188], [0.26303437123782614, 0.02477620234532174, 0.9947822450199725, 0.5916822332583692], [0.7523977891797228, 0.6198410071512576, 0.05799276940261333, 0.4181042411131305]], [[0.21564211884049145, 0.30667940527138227, 0.03010277335333611, 0.904264028183912], [0.33977550248572597, 0.042594462434406455, 0.6371061749651907, 0.8639246364627866], [0.009159271907318911, 0.054475512265855563, 0.7109847662274855, 0.9695933487818381]]]
1362
- [[[1, 6, 0, 1], [0, 4, 8, 3], [2, 4, 2, 8]], [[9, 7, 0, 6], [6, 2, 4, 6], [2, 2, 0, 1]]]
1363
- [[[4.281963231653285, 7.6564706580977155, 2.7831005401808904, 4.69275453971821], [7.731377457312142, 7.026081604862776, 3.1623746844355916, 4.097454457127405], [1.0053860355938644, 8.396390096875859, 5.860124932392565, 0.7556741321519111]], [[3.0505373562186717, 5.846422325897977, 5.79128924014881, 5.322513543793011], [7.97334322055796, 0.4266873959996582, 6.217219949795519, 2.819046997201407], [7.195256735457888, 3.205909055908082, 2.9903485221015123, 6.695032815286013]]]
1307
+ [[[0.015128082827448793, -0.731558889632968, -0.23379102528494308, 0.5923285646572862], [0.6389462900078073, -1.6347914510943111, 2.3694029836271726, -0.568526047386569], [-1.4229328154353735, 0.45185125607678145, -0.4003256267251042, -1.1425679894907612]], [[1.2876668616276734, 0.934232416262927, -1.4096609242818299, 0.2683613962988281], [0.3503627719719857, 1.9613965063102903, -2.0790609695353077, -0.10339725500993839], [-0.9334087233797456, 1.1394611182611, 1.3341558691128073, -0.3838574172857678]]]
1308
+ [[[0.8274205130045614, 0.27524584776494854, 0.715710895889572, 0.5807271906102146], [0.21742840470887725, 0.04577819370109826, 0.873689463957162, 0.04119770233167375], [0.554823367037196, 0.5901404246422433, 0.21342393541488192, 0.2979716283166385]], [[0.6045948602408673, 0.265586003384665, 0.9646655285283718, 0.9873208424367568], [0.16916505841642293, 0.15942804932580645, 0.679004396069304, 0.4586819952716237], [0.6058239213086706, 0.37021967026096103, 0.0015603885735545608, 0.8432925281217005]]]
1309
+ [[[7, 2, 9, 7], [0, 5, 1, 3], [9, 1, 0, 2]], [[1, 2, 7, 5], [5, 7, 4, 1], [2, 5, 7, 9]]]
1310
+ [[[1.6682230173222767, 0.5174279535822173, 6.202024157209834, 5.097176032335483], [3.44538825088208, 3.7119354081208025, 4.584800897579607, 8.294514147889751], [7.201908571787272, 4.96544760729807, 5.896259095293225, 3.215472062129558]], [[6.352678024277219, 6.894646335413341, 2.0445980257056333, 1.5835361381716893], [6.363077167625872, 8.831103031792672, 6.229821243776864, 0.5639371628314593], [7.639545178199688, 8.079077083978365, 8.063058392021144, 8.673394953496695]]]
1364
1311
  """
1365
1312
 
1366
1313
  print(regression.lin_reg(list(range(5)), [2, 4, 6, 7, 8]))
@@ -1385,19 +1332,8 @@ print(tools.linspace(0, 2.8, 8))
1385
1332
  [0.0, 0.39999999999999997, 0.7999999999999999, 1.2, 1.5999999999999999, 1.9999999999999998, 2.4, 2.8]
1386
1333
  """
1387
1334
 
1388
- # 提示:
1389
- #
1390
- # 测试已成功通过并结束。
1391
- #
1392
- # 这些测试只是这个包功能的一部分。
1393
- #
1394
- # 更多的功能需要自己探索和尝试!
1395
- #
1396
1335
  # Tip:
1397
- #
1398
1336
  # The test has been successfully passed and ended.
1399
- #
1400
1337
  # These tests are only part of the functionality of this package.
1401
- #
1402
1338
  # More features need to be explored and tried by yourself!
1403
1339
  ```
@@ -4,28 +4,28 @@ pypynum/Geometry.py,sha256=bJCuif-wHO-t7oHFEE7ntzIdQwzUEbT3mcKgmBV6Wps,13982
4
4
  pypynum/Graph.py,sha256=m9iTCNYRCZmAexDzwJ8Y6J7v1aweT-6TZkqh4fOtZDE,10131
5
5
  pypynum/Group.py,sha256=kzUR_r10ubOB2o51rKKdQPHRsgdTGL2yoY7yseKInZc,4263
6
6
  pypynum/Logic.py,sha256=IJAv59ECHU0HmG9lYCAQ_puqeL6Zor3-IDIVH48KBWE,11000
7
- pypynum/Matrix.py,sha256=TCq8Tjz5OjhbMkkEbGFgTgnT_UyQxDHbMj8OEFeJm9M,20408
7
+ pypynum/Matrix.py,sha256=_MMb2HsarLzPRGIR2tI4G7yPPvYpjIODYMgf6wdQmxw,20344
8
8
  pypynum/NeuralN.py,sha256=iSOvC9JW1h4AFGokGGOTkKie5hAYN_YT9H4f3apI9b8,3275
9
9
  pypynum/PyPyNum.png,sha256=t96tJPWfHxT8kcXm_qZI2z5W36TgOqjCU9qdgbmlFws,11623
10
10
  pypynum/Quaternion.py,sha256=-BW_crP_i-veHN0_pD3Z1dipFNUX198oZDrUYTsoZw0,8017
11
- pypynum/README.md,sha256=uJCs7gfD9uWGtTux3ux69PLf_0d1sF_phuoZvupwb8k,77877
11
+ pypynum/README.md,sha256=6WXIDNu_Tc5fHBpNIbzDCV8PWszDFCivzKenPuYc660,74771
12
12
  pypynum/Symbolics.py,sha256=u-Dig3OLs6qoLzxMpTAYJGq5uSWDMvgU13TAHKLyjMY,2768
13
13
  pypynum/Tensor.py,sha256=gi7OjrGgP5BSJS9Oma1B2EdX9qSpMNIP2BnKLojdT78,3930
14
14
  pypynum/Tree.py,sha256=BYnlb2kKNJ8kkuq8BAHIcLvPZw5KHxbvM7YuVGhQVMk,4330
15
15
  pypynum/Vector.py,sha256=ee-gkBtyG0l5dLFwAKRTTlnDG05pWpM19RGN7VoPvqE,3212
16
- pypynum/__init__.py,sha256=z13AowFFRvmI0WjXZ-6hOFlJSxJZRGUapW2B0EBpFXM,2896
16
+ pypynum/__init__.py,sha256=TqL88yyyOIW5Jp54b4ZqS1jr3J9bwo9VWLBDkh8ied8,2896
17
17
  pypynum/chars.py,sha256=ZOXZn2VzxmpHuvZ87ojhEib3CfTNgysRsFMFITHOA2E,2179
18
18
  pypynum/cipher.py,sha256=DaitY3DCoTuzyrXtD8Ap3IYDLhlMc7-o4AJfLlicvB4,10011
19
19
  pypynum/confs.py,sha256=iFz83iZ1A4BK4LTqo-ZbpAcoxhYWUxtEQKsr_-d8ryw,2869
20
20
  pypynum/constants.py,sha256=xELv4DIKEqBdwF9tUqCmTQVbgVrlrj385ht5eawvshU,1406
21
21
  pypynum/dists.py,sha256=WHDeM0oC4Do77p9TVVMu3pgWzI04gYdK_s1TNGhets0,29697
22
22
  pypynum/equations.py,sha256=26XEQBIcL3cyPLO6YFvBK1dlFHw-du3nQG4-cXAFYe0,557
23
- pypynum/errors.py,sha256=I3nh5YD5F_sBoa7hjPJi81goRflbVAZcjtmW7O2BhJk,220
23
+ pypynum/errors.py,sha256=XlK5yazNbNtnbM4toT_bdI41u-q-AUkZsa7dqc5dQb0,264
24
24
  pypynum/file.py,sha256=-sg3pndZdiyM8cS6KeIhCvB6NfAovHnLOhEf0XkjidE,3411
25
25
  pypynum/image.py,sha256=nhTZmaBVIKhuar-CcwZWb-hRYmkj4b_g7vIlYvEJEEE,12155
26
- pypynum/interp.py,sha256=PweAmBFCDpHtpo8GJxUdmpZ2DQY9C5HmmQ9zMWKQPV4,4896
26
+ pypynum/interp.py,sha256=X1LN4WiVYkZlyKXvK_KJ2KDgjDiW_-tqgFM4ySQ3yJk,4897
27
27
  pypynum/maths.py,sha256=cERFo7YK191xZ3JnshzXk4am9maTJUIeIEf1zIQitIM,31764
28
- pypynum/multiprec.py,sha256=OVlfOfFx00OzgWVy0m3ZCtKvlR7g_1-bola6gyQwEl0,16844
28
+ pypynum/multiprec.py,sha256=W4G48VXsTs13VFolcTjcE_BHQWccdl2PlC5coAT4V90,18405
29
29
  pypynum/numbers.py,sha256=PqQ07TWfcNlfjCjUg1UJda-BI1uOffmQVK1qIGbll_s,8619
30
30
  pypynum/plotting.py,sha256=mbIYK5TpY1qvuMJrqz4d8bxJEiZww3AI684vSKV-DgU,7781
31
31
  pypynum/polynomial.py,sha256=60hDQG_iRwduFFqawSTzAG6F3eHqfgrSnSGDwBLQB-s,14587
@@ -34,14 +34,14 @@ pypynum/random.py,sha256=qy2ISoHQVJ-zOVITplmCGvWEw-EZc18r-hZl8dvDimE,2274
34
34
  pypynum/regression.py,sha256=PfTM8glJSi3Jgvc_C_3hQBeVjkbrzSuDqRbEf3s403w,2040
35
35
  pypynum/sequence.py,sha256=7NSZm_p_B00KFj5XZrtSm2FXhsowxs0qg_Q_P4pAA8o,7194
36
36
  pypynum/stattest.py,sha256=W1041KeVsvdcLKFJOK4hQm_DjO5ZjUE8WEmGUe-4_Zk,5507
37
- pypynum/test.py,sha256=hkLxhtBl9XVjaqcbzDPEuYB92vDXfM9f7AS3tF5FSEE,9005
37
+ pypynum/test.py,sha256=tjJI8YkAqNEtwNeFsixWliZfc3J1qVpgCo4u-Wh9kvw,8826
38
38
  pypynum/this.py,sha256=oRX1OpMa4NJmQSdEjJxfszEo5FRYlxRiF8OTDRIcdMA,2154
39
- pypynum/tools.py,sha256=dEUgRxCahVm-fk8fRxrLqylLAHZygjWbmKmB9Nw_RZk,11395
39
+ pypynum/tools.py,sha256=0k8ZC-LcZ9BZqPYV487aPr95K1EoX-oHOalWjg9or3Y,12554
40
40
  pypynum/types.py,sha256=ek9tydfCspsjcvxVFv_rJegnTHl6PHwKPdqjvHfkvDg,246
41
41
  pypynum/ufuncs.py,sha256=g2tewdsGa4VrIq2khR-0SWJoXBitVRN87DulOnTxxDA,2572
42
42
  pypynum/utils.py,sha256=OqUFVraYDTSubF9QhZm8WC6A0ppnkhVU0YtAeYN9EyU,21048
43
43
  pypynum/zh_cn.py,sha256=Ky9AWuW64Vbhg_Pdn0Yksls7IEM_zk7uz1bb4iKmGNc,13008
44
- PyPyNum-1.13.0.dist-info/METADATA,sha256=P9M8A3kV5TxksHjXsOO3yuxd1lQIA1UwKNGq6ZWIml8,92256
45
- PyPyNum-1.13.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
46
- PyPyNum-1.13.0.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
47
- PyPyNum-1.13.0.dist-info/RECORD,,
44
+ PyPyNum-1.13.1.dist-info/METADATA,sha256=obf7t8Nu3EQH3DUm9tWPCgJYuvzNQVtlagsQpvCsS1c,89150
45
+ PyPyNum-1.13.1.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
46
+ PyPyNum-1.13.1.dist-info/top_level.txt,sha256=4wW_Xb4bRglmiMsdPAe9f75MkXhNpuN88H17g_Cr5u8,8
47
+ PyPyNum-1.13.1.dist-info/RECORD,,
pypynum/Matrix.py CHANGED
@@ -356,7 +356,7 @@ def hessenberg(matrix: Matrix) -> tuple:
356
356
  continue
357
357
  h = 0.0
358
358
  for k in range(0, i):
359
- a[i, k] = a[i, k] * scale_inv
359
+ a[i, k] *= scale_inv
360
360
  rr, ii = a[i, k].real, a[i, k].imag
361
361
  h += rr * rr + ii * ii
362
362
  f = a[i, i - 1]
@@ -373,7 +373,7 @@ def hessenberg(matrix: Matrix) -> tuple:
373
373
  h = 1 / sqrt(h)
374
374
  t[i] *= h
375
375
  for k in range(0, i - 1):
376
- a[i, k] = a[i, k] * h
376
+ a[i, k] *= h
377
377
  for j in range(0, i):
378
378
  g = t[i].conjugate() * a[j, i - 1]
379
379
  for k in range(0, i - 1):
@@ -547,7 +547,7 @@ def eigen(matrix: Matrix) -> tuple:
547
547
 
548
548
 
549
549
  def svd(matrix: Matrix) -> tuple:
550
- print("\n警告:SVD函数可能存在计算错误\n\nWarning: The SVD function may have calculation errors\n")
550
+ print("\nWarning: The SVD function may have calculation errors\n")
551
551
  e0, u = eigen(matrix @ matrix.t())
552
552
  u = Matrix([_[::-1] for _ in u])
553
553
  e1, v = eigen(matrix.t() @ matrix)
pypynum/README.md CHANGED
@@ -20,7 +20,7 @@ processing.</font><font color = red>[Python>=3.4]</font>
20
20
  [![Downloads](https://static.pepy.tech/badge/pypynum/month)](https://pepy.tech/project/pypynum)
21
21
  [![Downloads](https://static.pepy.tech/badge/pypynum/week)](https://pepy.tech/project/pypynum)
22
22
 
23
- ## Version -> 1.13.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
23
+ ## Version -> 1.13.1 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum | GitHub -> https://github.com/PythonSJL/PyPyNum
24
24
 
25
25
  ![LOGO](PyPyNum.png)
26
26
 
@@ -125,102 +125,48 @@ Python interpreter and run it!
125
125
  ```
126
126
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
127
127
 
128
- multiprec模块新增了一些函数
128
+ 修正了MPComplex的错误并且新增了部分用
129
+ 于计算三角函数的方法
129
130
 
130
- The multiprec module has added some new functions
131
+ Corrected errors in MPComplex
132
+ and added some methods for
133
+ calculating trigonometric
134
+ functions
131
135
 
132
- asmpc(real: Union[int, float, str, decimal.Decimal, complex, pypynum.multiprec.MPComplex], imag: Union[int, float, str, decimal.Decimal] = 0, sigfigs: int = 28) -> pypynum.multiprec.MPComplex
133
- mp_acos(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
134
- mp_asin(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
135
- mp_fresnel_c(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
136
- mp_fresnel_s(x: Union[int, float, str, decimal.Decimal], sigfigs: int) -> decimal.Decimal
136
+ !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
137
137
 
138
+ 增加了levenshtein_distance函数
138
139
 
139
- 新增了MPComplex类,
140
- 其实现了多精度复数计算,
141
- 目前支持加、减、乘、除、指数、对数等运算,
142
- 并且将在后面的版本增加各种三角函数。
140
+ Added levenshtein_distance function
143
141
 
144
- The MPComplex class has been added,
145
- which implements multi precision complex calculations.
146
- Currently,
147
- it supports operations such as addition,
148
- subtraction,
149
- multiplication,
150
- division,
151
- exponentiation,
152
- and logarithm,
153
- and various trigonometric functions will be added in later versions.
154
142
 
155
- MPComplex(real, imag, sigfigs=28)
143
+ Help on function levenshtein_distance in module pypynum.tools:
156
144
 
145
+ levenshtein_distance(s1: str, s2: str) -> int
146
+ Introduction
147
+ ==========
148
+ Calculate the Levenshtein distance between two strings.
157
149
 
158
- 创建多精度复数时建议使用asmpc函数,
159
- 因为它可以更方便地把其他数值类型转换为MPComplex对象。
150
+ The Levenshtein distance is a measure of the difference between two strings. It is defined as the minimum number
151
+ of single-character edits (i.e., insertions, deletions or substitutions) required to change one string into the
152
+ other.
160
153
 
161
- It is recommended to use the asmpc function when creating multi precision complex numbers,
162
- as it can more easily convert other numerical types to MPComplex objects.
154
+ Example
155
+ ==========
156
+ >>> levenshtein_distance("kitten", "sitting")
157
+ 3
158
+ >>>
159
+ :param s1: First string to compare.
160
+ :param s2: Second string to compare.
161
+ :return: The Levenshtein distance between the two strings.
163
162
 
164
163
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
165
164
 
166
- 移除了pypynum.tools.interp函数,改名为interp1d,
167
- 与新增的interp2d函数置于新的子模块——pypynum.interp。
168
-
169
- Removed the pypynum.tools.interp function and renamed it interp1d,
170
- placing it in a new submodule - pypynum.interp - along with the newly added interp2d function.
171
-
172
-
173
- Help on module pypynum.interp in pypynum:
174
-
175
- NAME
176
- pypynum.interp
177
-
178
- FUNCTIONS
179
- bicubic(x)
180
- Calculate the cubic B-spline interpolation function value.
181
- :param x: The x value for which the B-spline function is evaluated.
182
- :return: The value of the cubic B-spline function at x.
183
-
184
- contribute(src, x, y, channels=None)
185
- Calculate the contribution of the source array at a specific point after bicubic interpolation.
186
- :param src: The source 2D array from which to interpolate.
187
- :param x: The x-coordinate of the point to interpolate.
188
- :param y: The y-coordinate of the point to interpolate.
189
- :param channels: The number of channels if src is a multichannel array.
190
- :return: The interpolated value at the point (x, y).
191
-
192
- interp1d(data: Union[list, tuple], length: int) -> list
193
- Introduction
194
- ==========
195
- One-dimensional data interpolation
196
-
197
- Example
198
- ==========
199
- >>> interp1d((2, 4, 4, 2), 6)
200
- [2, 3.320000000000001, 4.160000000000005, 4.160000000000012, 3.3200000000000074, 2]
201
- >>>
202
- :param data: List of data points to be interpolated. Must be at least two points.
203
- :param length: The number of points in the resampled data set.
204
- :return: A list of interpolated values at the new points.
205
-
206
- interp2d(src, new_height, new_width, channels=None, round_res=False, min_val=None, max_val=None)
207
- Introduction
208
- ==========
209
- Two-dimensional data interpolation using bicubic spline interpolation.
210
-
211
- Example
212
- ==========
213
- >>> interp2d([[1, 2], [3, 4]], 3, 3)
214
- [[1.0, 1.6875, 2.0], [2.25, 3.1640625, 3.375], [3.0, 3.9375, 4.0]]
215
- >>>
216
- :param src: The source 2D array to be interpolated.
217
- :param new_height: The desired height of the interpolated array.
218
- :param new_width: The desired width of the interpolated array.
219
- :param channels: The number of channels if src is a multichannel array.
220
- :param round_res: Whether to round the result to the nearest integer.
221
- :param min_val: The minimum value to clip the interpolated results.
222
- :param max_val: The maximum value to clip the interpolated results.
223
- :return: A 2D array of the interpolated values with the new dimensions.
165
+ 注意:以后的版本中的自述文件将更改为纯英文
166
+
167
+ Attention: The self description
168
+ file in future versions will be
169
+ changed to pure English
224
170
 
225
171
  !=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
226
172
  ```
@@ -662,6 +608,7 @@ PyPyNum
662
608
  │ ├── generate_primes(limit: int) -> list
663
609
  │ ├── generate_semiprimes(limit: int) -> list
664
610
  │ ├── geomspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
611
+ │ ├── levenshtein_distance(s1: str, s2: str) -> int
665
612
  │ ├── linspace(start: typing.Union[int, float], stop: typing.Union[int, float], number: int) -> list
666
613
  │ ├── magic_square(n: Any) -> Any
667
614
  │ ├── primality(n: int, iter_num: int) -> bool
@@ -1042,8 +989,8 @@ print(equations.poly_eq(p))
1042
989
  print(equations.lin_eq(*m))
1043
990
 
1044
991
  """
1045
- [(-1.5615528128088307-6.5209667308287455e-24j) (1.0000000000000007+3.241554513744382e-25j) (2.5615528128088294+4.456233626665941e-24j)]
1046
- [ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
992
+ [(-1.5615528128088307-6.5209667308287455e-24j), (1.0000000000000007+3.241554513744382e-25j), (2.5615528128088294+4.456233626665941e-24j)]
993
+ [1.6666666666666665, -0.6666666666666666, -0.4444444444444444]
1047
994
  """
1048
995
 
1049
996
  print(maths.cot(constants.pi / 3))
@@ -1143,10 +1090,10 @@ print(random.randint(0, 9, [2, 3, 4]))
1143
1090
  print(random.uniform(0, 9, [2, 3, 4]))
1144
1091
 
1145
1092
  """
1146
- [[[1.0022026821190488, -0.38242004448759154, -0.23648445523561967, 0.43813038741951754], [-0.3778652198785619, -0.03865603124657112, -1.5186239424691736, -0.7368762975012327], [-0.7580654190380791, -1.3672869759158346, 0.582588816791107, 1.0281649895276377]], [[0.5270622699930536, 0.6132250709048543, 0.9764619731696673, -0.13740454362420268], [-2.0801461607759886, -0.1935521020633617, 0.44420106801354153, 1.4830089202063659], [-0.8790685594194517, 0.45517163054358967, -1.1448643981658326, 0.986414969442009]]]
1147
- [[[0.13698864758140294, 0.634190467772759, 0.25683276170297875, 0.9026812741081188], [0.26303437123782614, 0.02477620234532174, 0.9947822450199725, 0.5916822332583692], [0.7523977891797228, 0.6198410071512576, 0.05799276940261333, 0.4181042411131305]], [[0.21564211884049145, 0.30667940527138227, 0.03010277335333611, 0.904264028183912], [0.33977550248572597, 0.042594462434406455, 0.6371061749651907, 0.8639246364627866], [0.009159271907318911, 0.054475512265855563, 0.7109847662274855, 0.9695933487818381]]]
1148
- [[[1, 6, 0, 1], [0, 4, 8, 3], [2, 4, 2, 8]], [[9, 7, 0, 6], [6, 2, 4, 6], [2, 2, 0, 1]]]
1149
- [[[4.281963231653285, 7.6564706580977155, 2.7831005401808904, 4.69275453971821], [7.731377457312142, 7.026081604862776, 3.1623746844355916, 4.097454457127405], [1.0053860355938644, 8.396390096875859, 5.860124932392565, 0.7556741321519111]], [[3.0505373562186717, 5.846422325897977, 5.79128924014881, 5.322513543793011], [7.97334322055796, 0.4266873959996582, 6.217219949795519, 2.819046997201407], [7.195256735457888, 3.205909055908082, 2.9903485221015123, 6.695032815286013]]]
1093
+ [[[0.015128082827448793, -0.731558889632968, -0.23379102528494308, 0.5923285646572862], [0.6389462900078073, -1.6347914510943111, 2.3694029836271726, -0.568526047386569], [-1.4229328154353735, 0.45185125607678145, -0.4003256267251042, -1.1425679894907612]], [[1.2876668616276734, 0.934232416262927, -1.4096609242818299, 0.2683613962988281], [0.3503627719719857, 1.9613965063102903, -2.0790609695353077, -0.10339725500993839], [-0.9334087233797456, 1.1394611182611, 1.3341558691128073, -0.3838574172857678]]]
1094
+ [[[0.8274205130045614, 0.27524584776494854, 0.715710895889572, 0.5807271906102146], [0.21742840470887725, 0.04577819370109826, 0.873689463957162, 0.04119770233167375], [0.554823367037196, 0.5901404246422433, 0.21342393541488192, 0.2979716283166385]], [[0.6045948602408673, 0.265586003384665, 0.9646655285283718, 0.9873208424367568], [0.16916505841642293, 0.15942804932580645, 0.679004396069304, 0.4586819952716237], [0.6058239213086706, 0.37021967026096103, 0.0015603885735545608, 0.8432925281217005]]]
1095
+ [[[7, 2, 9, 7], [0, 5, 1, 3], [9, 1, 0, 2]], [[1, 2, 7, 5], [5, 7, 4, 1], [2, 5, 7, 9]]]
1096
+ [[[1.6682230173222767, 0.5174279535822173, 6.202024157209834, 5.097176032335483], [3.44538825088208, 3.7119354081208025, 4.584800897579607, 8.294514147889751], [7.201908571787272, 4.96544760729807, 5.896259095293225, 3.215472062129558]], [[6.352678024277219, 6.894646335413341, 2.0445980257056333, 1.5835361381716893], [6.363077167625872, 8.831103031792672, 6.229821243776864, 0.5639371628314593], [7.639545178199688, 8.079077083978365, 8.063058392021144, 8.673394953496695]]]
1150
1097
  """
1151
1098
 
1152
1099
  print(regression.lin_reg(list(range(5)), [2, 4, 6, 7, 8]))
@@ -1171,19 +1118,8 @@ print(tools.linspace(0, 2.8, 8))
1171
1118
  [0.0, 0.39999999999999997, 0.7999999999999999, 1.2, 1.5999999999999999, 1.9999999999999998, 2.4, 2.8]
1172
1119
  """
1173
1120
 
1174
- # 提示:
1175
- #
1176
- # 测试已成功通过并结束。
1177
- #
1178
- # 这些测试只是这个包功能的一部分。
1179
- #
1180
- # 更多的功能需要自己探索和尝试!
1181
- #
1182
1121
  # Tip:
1183
- #
1184
1122
  # The test has been successfully passed and ended.
1185
- #
1186
1123
  # These tests are only part of the functionality of this package.
1187
- #
1188
1124
  # More features need to be explored and tried by yourself!
1189
1125
  ```
pypynum/__init__.py CHANGED
@@ -66,7 +66,7 @@ from .utils import OrderedSet, InfIterator, LinkedList, IntervalSet
66
66
  from .Vector import vec
67
67
  from . import zh_cn
68
68
 
69
- __version__ = "1.13.0"
69
+ __version__ = "1.13.1"
70
70
  print("PyPyNum", "Version -> " + __version__, "PyPI -> https://pypi.org/project/PyPyNum/",
71
71
  "Gitee -> https://www.gitee.com/PythonSJL/PyPyNum", "GitHub -> https://github.com/PythonSJL/PyPyNum", sep=" | ")
72
72
  del math, arr, ite, num, prec, real, geom, ContentError, RandomError, LogicError, InputError, FullError, Union
pypynum/errors.py CHANGED
@@ -17,3 +17,7 @@ class RandomError(ValueError):
17
17
 
18
18
  class ShapeError(ValueError):
19
19
  pass
20
+
21
+
22
+ class ArgsError(ValueError):
23
+ pass
pypynum/interp.py CHANGED
@@ -6,7 +6,7 @@ def interp1d(data: arr, length: int) -> list:
6
6
  """
7
7
  Introduction
8
8
  ==========
9
- One-dimensional data interpolation
9
+ One-dimensional data interpolation.
10
10
 
11
11
  Example
12
12
  ==========
pypynum/multiprec.py CHANGED
@@ -399,21 +399,21 @@ class MPComplex:
399
399
  self.sigfigs = sigfigs
400
400
 
401
401
  def __add__(self, other):
402
- other = asmpc(other, self.sigfigs)
402
+ other = asmpc(other, sigfigs=self.sigfigs)
403
403
  return MPComplex(self.real + other.real, self.imag + other.imag, self.sigfigs)
404
404
 
405
405
  def __sub__(self, other):
406
- other = asmpc(other, self.sigfigs)
406
+ other = asmpc(other, sigfigs=self.sigfigs)
407
407
  return MPComplex(self.real - other.real, self.imag - other.imag, self.sigfigs)
408
408
 
409
409
  def __mul__(self, other):
410
- other = asmpc(other, self.sigfigs)
410
+ other = asmpc(other, sigfigs=self.sigfigs)
411
411
  real = self.real * other.real - self.imag * other.imag
412
412
  imag = self.real * other.imag + self.imag * other.real
413
413
  return MPComplex(real, imag, self.sigfigs)
414
414
 
415
415
  def __truediv__(self, other):
416
- other = asmpc(other, self.sigfigs)
416
+ other = asmpc(other, sigfigs=self.sigfigs)
417
417
  if other.real == 0 and other.imag == 0:
418
418
  raise ZeroDivisionError("Cannot divide by zero")
419
419
  else:
@@ -513,6 +513,40 @@ class MPComplex:
513
513
  def __repr__(self):
514
514
  return "MPComplex({!r}, {!r}, sigfigs={!r})".format(self.real, self.imag, self.sigfigs)
515
515
 
516
+ def sin(self):
517
+ real_part = mp_sin(self.real, self.sigfigs + 5) * mp_cosh(self.imag, self.sigfigs + 5)
518
+ imag_part = mp_cos(self.real, self.sigfigs + 5) * mp_sinh(self.imag, self.sigfigs + 5)
519
+ return MPComplex(real_part, imag_part, self.sigfigs)
520
+
521
+ def cos(self):
522
+ real_part = mp_cos(self.real, self.sigfigs + 5) * mp_cosh(self.imag, self.sigfigs + 5)
523
+ imag_part = -mp_sin(self.real, self.sigfigs + 5) * mp_sinh(self.imag, self.sigfigs + 5)
524
+ return MPComplex(real_part, imag_part, self.sigfigs)
525
+
526
+ def tan(self):
527
+ cos_z = self.cos()
528
+ if cos_z.real == 0 and cos_z.imag == 0:
529
+ raise ZeroDivisionError("Cosine of the complex number is zero, cannot compute tangent")
530
+ return self.sin() / cos_z
531
+
532
+ def cot(self):
533
+ sin_z = self.sin()
534
+ if sin_z.real == 0 and sin_z.imag == 0:
535
+ raise ZeroDivisionError("Sine of the complex number is zero, cannot compute cotangent")
536
+ return self.cos() / sin_z
537
+
538
+ def sec(self):
539
+ cos_z = self.cos()
540
+ if cos_z.real == 0 and cos_z.imag == 0:
541
+ raise ZeroDivisionError("Cosine of the complex number is zero, cannot compute secant")
542
+ return MPComplex(1, 0, self.sigfigs) / cos_z
543
+
544
+ def csc(self):
545
+ sin_z = self.sin()
546
+ if sin_z.real == 0 and sin_z.imag == 0:
547
+ raise ZeroDivisionError("Sine of the complex number is zero, cannot compute cosecant")
548
+ return MPComplex(1, 0, self.sigfigs) / sin_z
549
+
516
550
 
517
551
  def _remove_trailing_zeros(value: Any) -> str:
518
552
  value_str = str(value).lower()
pypynum/test.py CHANGED
@@ -323,19 +323,8 @@ for _ in list(globals().keys()):
323
323
  del _
324
324
 
325
325
  print("""\033[91m
326
- # 提示:
327
- #
328
- # 测试已成功通过并结束。
329
- #
330
- # 这些测试只是这个包功能的一部分。
331
- #
332
- # 更多的功能需要自己探索和尝试!
333
- #
334
326
  # Tip:
335
- #
336
327
  # The test has been successfully passed and ended.
337
- #
338
328
  # These tests are only part of the functionality of this package.
339
- #
340
329
  # More features need to be explored and tried by yourself!
341
330
  \033[m""")
pypynum/tools.py CHANGED
@@ -409,6 +409,39 @@ def magic_square(n):
409
409
  return result
410
410
 
411
411
 
412
+ def levenshtein_distance(s1: str, s2: str) -> int:
413
+ """
414
+ Introduction
415
+ ==========
416
+ Calculate the Levenshtein distance between two strings.
417
+
418
+ The Levenshtein distance is a measure of the difference between two strings. It is defined as the minimum number
419
+ of single-character edits (i.e., insertions, deletions or substitutions) required to change one string into the
420
+ other.
421
+
422
+ Example
423
+ ==========
424
+ >>> levenshtein_distance("kitten", "sitting")
425
+ 3
426
+ >>>
427
+ :param s1: First string to compare.
428
+ :param s2: Second string to compare.
429
+ :return: The Levenshtein distance between the two strings.
430
+ """
431
+ if len(s1) > len(s2):
432
+ s1, s2 = s2, s1
433
+ previous_row = list(range(len(s1) + 1))
434
+ for i2, c2 in enumerate(s2):
435
+ current_row = [i2 + 1]
436
+ for i1, c1 in enumerate(s1):
437
+ insertions = previous_row[i1 + 1] + 1
438
+ deletions = current_row[i1] + 1
439
+ substitutions = previous_row[i1] + (c1 != c2)
440
+ current_row.append(min(insertions, deletions, substitutions))
441
+ previous_row = current_row
442
+ return previous_row[-1]
443
+
444
+
412
445
  if __name__ == "__main__":
413
446
  import doctest
414
447