Mathematical Functions#
Mathematical functions operating element-wise on arrays.
Trigonometric Functions#
Function |
Description |
Example |
|---|---|---|
sin(x) |
Sine |
|
cos(x) |
Cosine |
|
tan(x) |
Tangent |
|
arcsin(x) |
Inverse sine |
|
arccos(x) |
Inverse cosine |
|
arctan(x) |
Inverse tangent |
|
arctan2(y, x) |
Four-quadrant inverse tangent |
|
hypot(x1, x2) |
Hypotenuse |
|
degrees(x) |
Convert radians to degrees |
|
radians(x) |
Convert degrees to radians |
Hyperbolic Functions#
Function |
Description |
Example |
|---|---|---|
sinh(x) |
Hyperbolic sine |
|
cosh(x) |
Hyperbolic cosine |
|
tanh(x) |
Hyperbolic tangent |
|
arcsinh(x) |
Inverse hyperbolic sine |
|
arccosh(x) |
Inverse hyperbolic cosine |
|
arctanh(x) |
Inverse hyperbolic tangent |
Exponential and Logarithmic#
Function |
Description |
Example |
|---|---|---|
exp(x) |
Exponential |
|
expm1(x) |
exp(x) - 1 |
|
exp2(x) |
2**x |
|
log(x) |
Natural logarithm |
|
log10(x) |
Base-10 logarithm |
|
log2(x) |
Base-2 logarithm |
|
log1p(x) |
log(1 + x) |
|
logaddexp(x1, x2) |
Log of sum of exponentials |
|
logaddexp2(x1, x2) |
Log base 2 of sum of exponentials |
Arithmetic Operations#
Function |
Description |
Example |
|---|---|---|
add(x1, x2) |
Add arguments element-wise |
|
subtract(x1, x2) |
Subtract arguments element-wise |
|
multiply(x1, x2) |
Multiply arguments element-wise |
|
divide(x1, x2) |
Divide arguments element-wise |
|
floor_divide(x1, x2) |
Floor division |
|
negative(x) |
Numerical negative |
|
positive(x) |
Numerical positive |
|
power(x1, x2) |
First array elements raised to powers |
|
remainder(x1, x2) |
Remainder of division |
|
mod(x1, x2) |
Remainder (alias for remainder) |
Rounding#
Function |
Description |
Example |
|---|---|---|
around(a, decimals) |
Round to given decimals |
|
round_(a, decimals) |
Round to given decimals |
|
rint(x) |
Round to nearest integer |
|
floor(x) |
Floor of input |
|
ceil(x) |
Ceiling of input |
|
trunc(x) |
Truncate to integer |
Miscellaneous#
Function |
Description |
Example |
|---|---|---|
sqrt(x) |
Square root |
|
cbrt(x) |
Cube root |
|
square(x) |
Square of input |
|
absolute(x) |
Absolute value |
|
fabs(x) |
Absolute value (floats) |
|
sign(x) |
Sign of elements |
|
maximum(x1, x2) |
Element-wise maximum |
|
minimum(x1, x2) |
Element-wise minimum |
|
clip(a, a_min, a_max) |
Clip values to range |
Code Examples#
The following examples are extracted from the test suite.
sqrt (test_sqrt_type_promotion.py:26)
16tests_run = 0
17tests_passed = 0
18tests_failed = 0
19
20def test_sqrt_int8_to_float64():
21 """Test int8 array promotes to float64"""
22 global tests_run, tests_passed, tests_failed
23 tests_run += 1
24
25 arr = test_bind.np.array([4, 9, 16, 25], dtype=test_bind.np.int8)
26 result = test_bind.numpycore.sqrt(arr)
27
28 if result.dtype != test_bind.np.float64:
29 test_bind.f_print_error(f"int8->float64: Expected float64, got {result.dtype}")
30 tests_failed += 1
31 return
32
33 if not (abs(result[0] - 2.0) < 1e-10 and abs(result[1] - 3.0) < 1e-10
34 and abs(result[2] - 4.0) < 1e-10 and abs(result[3] - 5.0) < 1e-10):
35 test_bind.f_print_error(f"int8->float64: Values incorrect")
36 tests_failed += 1