Fonctions mathématiques

Statistiques descritives

Arrondis

x = np.array([[0.2, 0.5, 1.2]])

# À l'entier en-dessous
print(np.floor(x))       # [[0. 0. 1.]]

# À l'entier au-dessus
print(np.ceil(x))        # [[1. 1. 2.]]

# À l'entier le plus proche
print(np.round(x))       # [[0. 0. 1.]]
print(np.floor(x + 0.5)) # [[0. 1. 1.]]

Produit matriciel

# Inner product
x = np.array([[1,2],[3,4]])
y = np.array([[10,20],[30,40]])

print(x.dot(y))
print(np.dot(x, y))
print(np.matmul(x, y))
'''
[[ 70 100]
 [150 220]]
'''
# Outer product
print(np.outer(x, y))
'''
[[ 10  20  30  40]
 [ 20  40  60  80]
 [ 30  60  90 120]
 [ 40  80 120 160]]
'''

Constantes

print(np.pi)           # 3.141592653589793
print(np.e)            # 2.718281828459045
print(np.euler_gamma)  # 0.5772156649015329
print(np.PINF)         # inf
print(np.NINF)         # -inf
print(np.NAN)          # nan
print(np.PZERO)        # 0.0
print(np.NZERO)        # -0.0

Fonctions universelles

np.negative(x)   # 1-X
np.square(x)     # Carré
np.sqrt(x)       # Racine carrée
np.abs(x)        # Valeur absolue
np.exp(x)        # Exponentielle
np.log(x)        # Log exp(x)
np.log1p(x)      # Log exp(x)-1
np.log10(x)      # Log 10
np.log2(x)       # Log 2

np.sin(x)        # Sinus
np.cos(x)        # Cosinus
np.tan(x)        # Tangente
np.hypot(x1, x2) # Hypothénuse

np.arcsin(x)
np.arccos(x)
np.arctan(x)
np.arctan2(x1, x2)

np.sinh(x)
np.cosh(x)
np.tanh(x)
np.arcsinh(x)
np.arccosh(x)
np.arctanh(x)

np.degrees(x)    # Radian -> degres
np.radians(x)    # Degres -> radians

Autres

# Greatest Common Denominator
print(np.gcd(6, 9)) # 3

print(np.gcd.reduce(np.array([6, 9, 15]))) # 3

# Lowest Common Multiple
print(np.lcm(6, 9)) # 18

print(np.lcm.reduce(np.array([6, 9, 15]))) # 90

Math functions
Linear Algebra
Linear Algebra examples