A Python math package written in pure Python programming language [python_requires >= 3.5]
Project description
PyPyNum
A Python math package written in pure Python programming language ( python_requires >= 3.5)
________ ___ ___ ________ ___ ___ ________ ___ ___ _____ ______
|\ __ \ |\ \ / /||\ __ \ |\ \ / /||\ ___ \ |\ \|\ \ |\ _ \ _ \
\ \ \|\ \\ \ \/ / /\ \ \|\ \\ \ \/ / /\ \ \\ \ \\ \ \\\ \\ \ \\\__\ \ \
\ \ ____\\ \ / / \ \ ____\\ \ / / \ \ \\ \ \\ \ \\\ \\ \ \\|__| \ \
\ \ \___| \/ / / \ \ \___| \/ / / \ \ \\ \ \\ \ \\\ \\ \ \ \ \ \
\ \__\ __/ / / \ \__\ __/ / / \ \__\\ \__\\ \_______\\ \__\ \ \__\
\|__| |\___/ / \|__| |\___/ / \|__| \|__| \|_______| \|__| \|__|
\|___|/ \|___|/
Version -> 1.5.0 | PyPI -> https://pypi.org/project/PyPyNum/ | Gitee -> https://www.gitee.com/PythonSJL/PyPyNum
介绍
Introduction
- DIY数学库,类似于numpy、scipy等,专为PyPy解释器制作
- DIY math library, similar to numpy, scipy, etc., specifically designed for PyPy interpreters
- 不定期更新版本,增加更多实用功能
- Update versions periodically to add more practical features
- 如需联系,QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
- If you need to contact, QQ 2261748025 (Py𝙿𝚢𝚝𝚑𝚘𝚗-水晶兰)
PyPyNum的Zen
The Zen of PyPyNum
The Zen of PyPyNum, by Shen Jiayi
This is a math package written purely in Python.
... (Do you want to see the entire content?
Then enter "from pypynum import this" on your
Python interpreter and run it!)
December 27, 2023
与上一个版本相比新增功能
New features compared to the previous version
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
“Symbolics”模块中的希腊字母字符串中存
在错误,已更正
There is an error in the Greek
letter string in the "Symbolics"
module, which has been corrected
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
傅立叶变换的类“FT1D”在数据末尾设置自动
零填充,直到数据长度达到2的正整数幂
The class "FT1D" of Fourier
transform sets automatic zero
padding at the end of the data
until the data length reaches a
positive integer power of 2
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
“plotting”模块中添加了一个非常有用的
“color”函数,可用于使字符串或其他类型
的数据着色。
A very useful "color" function
has been added to the "plotting"
module, which can be used to
make strings or other types of
data colored.
您可以使用此函数为字符上色,然后将其用作
绘制函数曲线的字符,并将“coloration”
参数设置为“True”(可能仅适用于
PyCharm等编程软件)
You can use this function to
color a character, then use it
as the character to draw the
function curve, and set the
"color" parameter to "True"
(which may only be applicable to
programming software like
PyCharm)
!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=!=
<The "+" indicates the newly added method>
[This is the base class of vectors, matrices, and tensors]
Array(data=None, check=True)
__add__(self, other)
__eq__(self, other)
__getitem__(self, item)
__hash__(self)
__init__(self, data=None, check=True)
__ne__(self, other)
__radd__(self, other)
__repr__(self)
__round__(self, n=None)
__str__(self)
argmax(self, axis=None) +
argmin(self, axis=None) +
basic(self, func, axis=None) +
copy(self)
flatten(self)
max(self, axis=None) +
mean(self, axis=None) +
median(self, axis=None) +
min(self, axis=None) +
mode(self, axis=None) +
product(self, axis=None) +
ptp(self, axis=None) +
reshape(self, shape)
std(self, axis=None) +
sum(self, axis=None) +
var(self, axis=None) +
maths [Mathematical functions]
root(x: num, y: num) -> num +
...
cumsum(lst: arr) -> list +
cumprod(lst: arr) -> list +
iroot(y: int, n: int) -> int +
<<< Other modules also have certain modifications >>>
运行用时测试
Run Time Test
矩阵用时测试 Matrix Time Test |
NumPy+CPython(seconds) | 排名 Ranking |
PyPyNum+PyPy(seconds) | 排名 Ranking |
Mpmath_+_PyPy_(_seconds_) | 排名 Ranking |
SymPy_+_PyPy_(_seconds_) | 排名 Ranking |
---|---|---|---|---|---|---|---|---|
创建一百阶随机数矩阵 Create a hundred order random number matrix |
0.000083 | 1 | 0.005374 | 2 | 0.075253 | 3 | 0.230530 | 4 |
创建一千阶随机数矩阵 Create a thousand order random number matrix |
0.006740 | 1 | 0.035666 | 2 | 1.200950 | 3 | 4.370265 | 4 |
一百阶矩阵相加 Addition of matrices of order one hundred |
0.000029 | 1 | 0.002163 | 2 | 0.045641 | 4 | 0.035700 | 3 |
一千阶矩阵相加 Adding matrices of order one thousand |
0.002647 | 1 | 0.019111 | 2 | 1.746957 | 4 | 0.771542 | 3 |
一百阶矩阵行列式 Determinant of a hundred order matrix |
0.087209 | 2 | 0.016331 | 1 | 4.354507 | 3 | 5.157206 | 4 |
一千阶矩阵行列式 Determinant of a thousand order matrix |
0.616113 | 1 | 3.509747 | 2 | 速度极慢 | 3 | 无法计算 | 4 |
一百阶矩阵求逆 Finding the inverse of a hundred order matrix |
0.162770 | 1 | 31.088849 | 4 | 8.162948 | 2 | 21.437424 | 3 |
一千阶矩阵求逆 Finding the inverse of a thousand order matrix |
0.598905 | 1 | 速度较慢 | 4 | 速度较慢 | 2 | 速度较慢 | 3 |
数组输出效果 Array output effect |
[[[[ -7 -67] [-78 29]] [[-86 -97] [ 68 -3]]] [[[ 11 42] [ 24 -65]] [[-60 72] [ 73 2]]]] |
/ | [[[[ 37 83] [ 40 2]] [[ -5 -34] [ -7 72]]] [[[ 13 -64] [ 6 90]] [[ 68 57] [ 78 11]]]] |
/ | [-80.0 -8.0 80.0 -88.0] [-99.0 -43.0 87.0 81.0] [ 20.0 -55.0 98.0 8.0] [ 8.0 44.0 64.0 -35.0] (只支持矩阵) (Only supports matrices) |
/ | ⎡⎡16 -56⎤ ⎡ 8 -28⎤⎤ ⎢⎢ ⎥ ⎢ ⎥⎥ ⎢⎣-56 56 ⎦ ⎣-28 28 ⎦⎥ ⎢ ⎥ ⎢ ⎡-2 7 ⎤ ⎡-18 63 ⎤⎥ ⎢ ⎢ ⎥ ⎢ ⎥⎥ ⎣ ⎣7 -7⎦ ⎣63 -63⎦⎦ |
/ |
基本结构
Basic structure
PyPyNum
★ __init__
[Import some features from other modules in this package]
★ errors [Special errors]
CLASSES
LogicError
RandomError
ShapeError
★ file [Reading and saving instance data]
FUNCTIONS
read(file: str) -> list
write(file: str, *cls: object)
★ test
[A code test file]
★ this
[The Zen of PyPyNum]
★ types [Special types]
DATA
arr = typing.Union[list, tuple]
ite = typing.Union[list, tuple, str]
num = typing.Union[int, float, complex]
real = typing.Union[int, float]
★ Array [N-dimensional array]
CLASSES
Array
FUNCTIONS
array(data=None)
fill(shape, sequence=None)
function(_array, _function, args=None)
get_shape(data)
is_valid_array(_array, _shape)
zeros(shape)
zeros_like(_nested_list)
★ FourierT [Fourier transform and inverse Fourier transform]
CLASSES
FT1D
★ Geometry [Planar geometry]
CLASSES
Circle
Line
Point
Polygon
Quadrilateral
Triangle
FUNCTIONS
distance(g1, g2, error: int | float = 0) -> float
★ Group [Group theory]
CLASSES
Group
FUNCTIONS
add(x, y)
divide(x, y)
group(data)
multiply(x, y)
subtract(x, y)
★ Logic [Logic circuit simulation]
CLASSES
Basic
Binary
AND
COMP
HalfAdder
HalfSuber
JKFF
NAND
NOR
OR
XNOR
XOR
Quaternary
TwoBDiver
TwoBMuler
Ternary
FullAdder
FullSuber
Unary
DFF
NOT
TFF
★ Matrix [Matrix calculation]
CLASSES
Matrix
FUNCTIONS
eig(matrix)
identity(n)
lu(matrix)
mat(data)
qr(matrix)
same(rows, cols, value=0)
svd(matrix)
tril_indices(n, k=0, m=None)
zeros(_dimensions)
zeros_like(_nested_list)
★ NeuralN [A simple neural network model]
CLASSES
NeuralNetwork
FUNCTIONS
neuraln(_input, _hidden, _output)
★ Quaternion [Quaternion calculation]
CLASSES
Euler
Quaternion
FUNCTIONS
change(data: Union[pypynum.Quaternion.Quaternion, pypynum.Matrix.Matrix, pypynum.Quaternion.Euler], to: str) -> Union[pypynum.Quaternion.Quaternion, pypynum.Matrix.Matrix, pypynum.Quaternion.Euler]
euler(yaw: Union[int, float] = 0, pitch: Union[int, float] = 0, roll: Union[int, float] = 0) -> pypynum.Quaternion.Euler
quat(w: Union[int, float] = 0, x: Union[int, float] = 0, y: Union[int, float] = 0, z: Union[int, float] = 0) -> pypynum.Quaternion.Quaternion
★ Symbolics [Symbol calculation]
FUNCTIONS
interpreter(expr: str) -> list
DATA
basic = '%()*+-./0123456789'
english = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
greek = 'ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψω'
operators = ['**', '*', '//', '/', '%', '+', '-']
valid = '%()*+-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcd...zΑΒΓΔΕΖΗΘΙ...'
★ Tensor [Tensor calculation]
CLASSES
Tensor
FUNCTIONS
ten(data)
tensor_and_number(tensor, operator, number)
tolist(_nested_list)
zeros(_dimensions)
zeros_like(_nested_list)
★ Vector [Vector calculation]
CLASSES
Vector
FUNCTIONS
same(length, value=0)
vec(data)
zeros(_dimensions)
zeros_like(_nested_list)
★ cipher [String encryption and decryption algorithms]
FUNCTIONS
dna(string: str, decrypt: bool = False) -> str
★ constants [Constants in mathematics and science]
DATA
AMU = 1.6605402e-27
EB = 1152921504606846976
G = 6.6743e-11
GB = 1073741824
KB = 1024
MB = 1048576
NA = 6.02214076e+23
PB = 1125899906842624
TB = 1099511627776
YB = 1208925819614629174706176
ZB = 1180591620717411303424
atto = 1e-18
c = 299792458
centi = 0.01
deci = 0.1
deka = 10.0
e = 2.718281828459045
exa = 1e+18
femto = 1e-15
gamma = 0.5772156649015329
giga = 1000000000.0
h = 6.62607015e-34
hecto = 100.0
inf = inf
kilo = 1000.0
mega = 1000000.0
micro = 1e-06
milli = 0.001
nan = nan
nano = 1e-09
peta = 1000000000000000.0
phi = 1.618033988749895
pi = 3.141592653589793
pico = 1e-12
qe = 1.60217733e-19
tera = 1000000000000.0
yocto = 1e-24
yotta = 1e+24
zepto = 1e-21
zetta = 1e+21
★ equations [Solving specific forms of equations]
FUNCTIONS
linear_equation(left: list, right: list) -> list
polynomial_equation(coefficients: list) -> list
★ maths [Mathematical functions]
FUNCTIONS
root(x: num, y: num) -> num
exp(x: real) -> real
ln(x: real) -> real
gcd(*args: int) -> int
lcm(*args: int) -> int
sin(x: real) -> real
cos(x: real) -> real
tan(x: real) -> real
csc(x: real) -> real
sec(x: real) -> real
cot(x: real) -> real
asin(x: real) -> real
acos(x: real) -> real
atan(x: real) -> real
acsc(x: real) -> real
asec(x: real) -> real
acot(x: real) -> real
sinh(x: real) -> real
cosh(x: real) -> real
tanh(x: real) -> real
csch(x: real) -> real
sech(x: real) -> real
coth(x: real) -> real
asinh(x: real) -> real
acosh(x: real) -> real
atanh(x: real) -> real
acsch(x: real) -> real
asech(x: real) -> real
acoth(x: real) -> real
ptp(numbers: arr) -> num
median(numbers: arr) -> num
freq(data: arr) -> dict
mode(data: arr)
mean(numbers: arr) -> num
var(numbers: arr) -> num
std(numbers: arr) -> num
product(numbers: arr) -> num
sigma(i: int, n: int, f) -> num
pi(i: int, n: int, f) -> num
derivative(f, x: real, h: real = 1e-7) -> float
definite_integral(f, x_start: real, x_end: real, n: int = 10000000) -> float
beta(p: real, q: real) -> real
gamma(alpha: real) -> float
factorial(n: int) -> int
arrangement(n: int, r: int) -> int
combination(n: int, r: int) -> int
zeta(alpha: real) -> float
gaussian(x: real, _mu: real = 0, _sigma: real = 1) -> float
poisson(x: int, _lambda: real) -> float
erf(x: real) -> float
sigmoid(x: real) -> float
sign(x: real) -> int
parity(x: int) -> int
cumsum(lst: arr) -> list
cumprod(lst: arr) -> list
iroot(y: int, n: int) -> int
★ plotting [Draw a graph of equations using characters]
FUNCTIONS
color(text: str, rgb: arr) -> str
change(data: thing) -> thing
background(right: real = 5, left: real = -5, top: real = 5, bottom: real = -5...
unary(function, right: real = 5, left: real = -5, top: real = 5, bottom: real = -5, complexity: real = 5...
binary(function, right: real = 5, left: real = -5, top: real = 5, bottom: real = -5, complexity: real = 5...
c_unary(function, start: real, end: real, interval: real = 5, projection: str = "ri", right: real = 5...
★ probability [Probability function]
FUNCTIONS
binomial(sample_size: int, successes: int, success_probability: Union[int, float]) -> float
hypergeometric(total_items: int, success_items: int, sample_size: int, successes_in_sample: int) -> float
★ random [Generate random numbers or random arrays]
FUNCTIONS
choice(seq: Union[list, tuple, str], shape: Union[list, tuple] = None)
gauss(mu: Union[int, float] = 0, sigma: Union[int, float] = 1, shape: Union[list, tuple] = None) -> Union[float, list]
gauss_error(original: Union[list, tuple], mu: Union[int, float] = 0, sigma: Union[int, float] = 1) -> list
rand(shape: Union[list, tuple] = None) -> Union[float, list]
randint(a: int, b: int, shape: Union[list, tuple] = None) -> Union[int, list]
uniform(a: Union[int, float], b: Union[int, float], shape: Union[list, tuple] = None) -> Union[float, list]
★ regression [Formula based polynomial regression]
FUNCTIONS
linear_regression(x: Union[list, tuple], y: Union[list, tuple]) -> list
parabolic_regression(x: Union[list, tuple], y: Union[list, tuple]) -> list
polynomial_regression(x: Union[list, tuple], y: Union[list, tuple], n: int = None) -> list
★ sequence [Various sequences]
FUNCTIONS
bernoulli(n: int, single: bool = True) -> list
catalan(n: int) -> int
fibonacci(n: int) -> int
★ tools [Other useful tools]
FUNCTIONS
classify(array: Union[list, tuple]) -> dict
deduplicate(iterable: Union[list, tuple, str]) -> Union[list, tuple, str]
frange(start: Union[int, float], stop: Union[int, float], step: float = 1.0) -> list
linspace(start: Union[int, float], stop: Union[int, float], number: int) -> list
split(iterable: Union[list, tuple, str], key: Union[list, tuple], retain: bool = False) -> list
代码测试
Code testing
>>> from pypynum import (Array, Geometry, Logic, Matrix, Quaternion, Symbolics, Tensor, Vector,
cipher, constants, equations, maths, plotting, random, regression, tools)
...
>>> print(Array.array())
>>> print(Array.array([1, 2, 3, 4, 5, 6, 7, 8]))
>>> print(Array.array([[1, 2, 3, 4], [5, 6, 7, 8]]))
>>> print(Array.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]]))
[]
[1 2 3 4 5 6 7 8]
[[1 2 3 4]
[5 6 7 8]]
[[[1 2]
[3 4]]
[[5 6]
[7 8]]]
>>> triangle = Geometry.Triangle((0, 0), (2, 2), (3, 0))
>>> print(triangle.perimeter())
>>> print(triangle.area())
>>> print(triangle.centroid())
8.06449510224598
3.0
(1.6666666666666667, 0.6666666666666666)
>>> a, b, c = 1, 1, 1
>>> adder0, adder1 = Logic.HalfAdder("alpha", a, b), Logic.HalfAdder("beta", c, None)
>>> xor0 = Logic.XOR("alpha")
>>> ff0, ff1 = Logic.DFF("alpha"), Logic.DFF("beta")
>>> xor0.set_order0(1)
>>> xor0.set_order1(1)
>>> Logic.connector(adder0, adder1)
>>> Logic.connector(adder0, xor0)
>>> Logic.connector(adder1, xor0)
>>> Logic.connector(adder1, ff0)
>>> Logic.connector(xor0, ff1)
>>> print("sum: {}, carry: {}".format(ff0.out(), ff1.out()))
sum: [1], carry: [1]
>>> m0 = Matrix.mat([[1, 2], [3, 4]])
>>> m1 = Matrix.mat([[5, 6], [7, 8]])
>>> print(m0)
>>> print(m1)
>>> print(m0 + m1)
>>> print(m0 @ m1)
>>> print(m0.inv())
>>> print(m1.rank())
[[1 2]
[3 4]]
[[5 6]
[7 8]]
[[ 6 8]
[10 12]]
[[19 22]
[43 50]]
[[-2.0 1.0]
[ 1.5 -0.5]]
2
>>> q0 = Quaternion.quat(1, 2, 3, 4)
>>> q1 = Quaternion.quat(5, 6, 7, 8)
>>> print(q0)
>>> print(q1)
>>> print(q0 + q1)
>>> print(q0 * q1)
>>> print(q0.inverse())
>>> print(q1.conjugate())
(1+2i+3j+4k)
(5+6i+7j+8k)
(6+8i+10j+12k)
(-60+12i+30j+24k)
(0.18257418583505536+-0.3651483716701107i+-0.5477225575051661j+-0.7302967433402214k)
(5+-6i+-7j+-8k)
>>> print(Symbolics.basic)
>>> print(Symbolics.english)
>>> print(Symbolics.greek)
>>> print(Symbolics.interpreter("-(10+a-(3.14+b0)*(-5))**(-ζn1-2.718/mΣ99)//9"))
%()*+-./0123456789
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩαβγδεζηθικλμνξοπρστυφχψω
[['10', '+', 'a', '-', ['3.14', '+', 'b0'], '*', '-5'], '**', ['-ζn1', '-', '2.718', '/', 'mΣ99'], '//', '9']
>>> t0 = Tensor.ten([[[1, 2], [3, 4]], [[5, 6], [7, 8]]])
>>> t1 = Tensor.ten([[[9, 10], [11, 12]], [[13, 14], [15, 16]]])
>>> print(t0)
>>> print(t1)
>>> print(t0 + t1)
>>> print(t0 @ t1)
[[[1 2]
[3 4]]
[[5 6]
[7 8]]]
[[[ 9 10]
[11 12]]
[[13 14]
[15 16]]]
[[[10 12]
[14 16]]
[[18 20]
[22 24]]]
[[[ 31 34]
[ 71 78]]
[[155 166]
[211 226]]]
>>> string = "PyPyNum"
>>> encrypted = cipher.dna(string)
>>> print(string)
>>> print(encrypted)
>>> print(cipher.dna(encrypted, decrypt=True))
PyPyNum
CCCTAGACCCTCGTCCCGCTAAACCCTG
PyPyNum
v0 = Vector.vec([1, 2, 3, 4])
v1 = Vector.vec([5, 6, 7, 8])
print(v0)
print(v1)
print(v0 + v1)
print(v0 @ v1)
print(v0.normalize())
print(v1.angles())
[1 2 3 4]
[5 6 7 8]
[ 5 12 21 32]
70
[0.18257418583505536 0.3651483716701107 0.5477225575051661 0.7302967433402214]
[1.1820279130506308, 1.0985826410133916, 1.0114070854293842, 0.9191723423169716]
>>> print(constants.TB)
>>> print(constants.e)
>>> print(constants.h)
>>> print(constants.phi)
>>> print(constants.pi)
>>> print(constants.tera)
1099511627776
2.718281828459045
6.62607015e-34
1.618033988749895
3.141592653589793
1000000000000.0
>>> p = [1, -2, -3, 4]
>>> m = [
[
[1, 2, 3],
[6, 10, 12],
[7, 16, 9]
],
[-1, -2, -3]
]
>>> print(equations.polynomial_equation(p))
>>> print(equations.linear_equation(*m))
[(-1.5615528128088307-6.5209667308287455e-24j) (2.5615528128088294+4.456233626665941e-24j) (1.0000000000000007+3.241554513744382e-25j)]
[ 1.6666666666666667 -0.6666666666666666 -0.4444444444444444]
>>> print(maths.cot(constants.pi / 3))
>>> print(maths.gamma(1.5))
>>> print(maths.pi(1, 10, lambda x: x ** 2))
>>> print(maths.product([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]))
>>> print(maths.sigma(1, 10, lambda x: x ** 2))
>>> print(maths.var([2, 3, 5, 7, 11, 13, 17, 19, 23, 29]))
0.577350269189626
0.886226925452758
13168189440000
6469693230
385
73.29
>>> plt = plotting.unary(lambda x: x ** 2, top=10, bottom=0, character="+")
>>> print(plt)
>>> print(plotting.binary(lambda x, y: x ** 2 + y ** 2 - 10, right=10, left=0, compare="<=", basic=plotting.change(plt)))
>>> print(plotting.c_unary(lambda x: x ** x, start=-10, end=10, interval=100, right=2, left=-2, top=2, bottom=-2, complexity=20, character="-"))
1.00e+01| + +
|
| + +
|
| + +
| + +
|
| + +
5.00e+00|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
| + +
| + +
| + +
| + +
| + +
| + +
| + +
| +++ +++
0.00e+00|________________________+++________________________
-5.00e+00 0.00e+00 5.00e+00
1.00e+01| + +
|
| + +
|
|......... + +
|............. +
|..............
|................ +
5.00e+00|................_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
|................ +
|................ +
|.............. + +
|............. + +
|......... + +
| + +
| + +
| +++ +++
0.00e+00|________________________+++________________________
-5.00e+00 0.00e+00 5.00e+00
2.00e+00|
|
|
|
|
|
|
|
|
| -------
| ------ -----
| ---- --
| --- --
0.00e+00|_ _ _ _ _ _ _ _ _ _ --_ _ _ _ _ _ _ _ _-- _ _-- _ _ _ ---------------------------
| -- ------- ---
| - --
| - -
| -- -
| -- -
| -- -
| --- ---
| ---- ----
| -------- -------
| ------------
|
|
|
-2.00e+00|_________________________________________________________________________________
-2.00e+00 0.00e+00 2.00e+00
>>> print(random.gauss(0, 1, [2, 3, 4]))
>>> print(random.rand([2, 3, 4]))
>>> print(random.randint(0, 9, [2, 3, 4]))
>>> print(random.uniform(0, 9, [2, 3, 4]))
[[[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]]]
[[[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]]]
[[[5, 9, 5, 6], [6, 7, 6, 1], [1, 3, 2, 4]], [[5, 8, 8, 3], [3, 2, 3, 9], [3, 0, 7, 1]]]
[[[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]]]
>>> print(regression.linear_regression(list(range(5)), [2, 4, 6, 7, 8]))
>>> print(regression.parabolic_regression(list(range(5)), [2, 4, 6, 7, 8]))
>>> print(regression.polynomial_regression(list(range(5)), [2, 4, 6, 7, 8], 4))
[1.5, 2.4000000000000004]
[-0.21428571428571183, 2.3571428571428474, 1.9714285714285764]
[0.08333333334800574, -0.6666666668092494, 1.4166666678382942, 1.1666666648311956, 2.0000000002900613]
>>> print(tools.classify([1, 2.3, 4 + 5j, "string", list, True, 3.14, False, tuple, tools]))
>>> print(tools.deduplicate(["Python", 6, "NumPy", int, "PyPyNum", 9, "pypynum", "NumPy", 6, True]))
>>> print(tools.frange(0, 3, 0.4))
>>> print(tools.linspace(0, 2.8, 8))
{<class 'int'>: [1], <class 'float'>: [2.3, 3.14], <class 'complex'>: [(4+5j)], <class 'str'>: ['string'], <class 'type'>: [<class 'list'>, <class 'tuple'>], <class 'bool'>: [True, False], <class 'module'>: [<module 'pypynum.tools' from 'F:\\PyPyproject\\PyPyproject1\\pypynum\\tools.py'>]}
['Python', 6, 'NumPy', <class 'int'>, 'PyPyNum', 9, 'pypynum', True]
[0.0, 0.4, 0.8, 1.2000000000000002, 1.6, 2.0, 2.4000000000000004, 2.8000000000000003]
[0.0, 0.39999999999999997, 0.7999999999999999, 1.2, 1.5999999999999999, 1.9999999999999998, 2.4, 2.8]
提示:
测试已成功通过并结束。
这些测试只是这个包功能的一部分。
更多的功能需要自己探索和尝试!
Tip:
The test has been successfully passed and ended.
These tests are only part of the functionality of this package.
More features need to be explored and tried by yourself!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
PyPyNum-1.5.0.tar.gz
(106.9 kB
view details)
Built Distribution
PyPyNum-1.5.0-py3-none-any.whl
(78.4 kB
view details)
File details
Details for the file PyPyNum-1.5.0.tar.gz
.
File metadata
- Download URL: PyPyNum-1.5.0.tar.gz
- Upload date:
- Size: 106.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e270e7731f3112f2f83361d2d693d8bcc40308a078dc37599648ecfb95a014b6 |
|
MD5 | f2fca4c8caadfb776016886b7a46b74d |
|
BLAKE2b-256 | 94b07d22878bf286fd85955ef84ece29afda7aabc180f9f048ab653f21b4fc6e |
File details
Details for the file PyPyNum-1.5.0-py3-none-any.whl
.
File metadata
- Download URL: PyPyNum-1.5.0-py3-none-any.whl
- Upload date:
- Size: 78.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db11ffdaf7d96aa3340e614d7eba9e19d010e1e1284cc756f264ebbda8a010e3 |
|
MD5 | 3a22174872603857f855f0584fe290f0 |
|
BLAKE2b-256 | 12aa002c02b3d8041569926c4cc382f0f23e6ebf68569282faff921a942e5398 |