Numeric functions

Numeric functions

abs(x) Take the absolute value of a numeric value or array.
exp(x) Computes e raised to the power x.
is_nan(x) Returns True if the argument is NaN (not a number).
log(x[, base]) Take the logarithm of the x with base base.
log10(x) Take the logarithm of the x with base 10.
sqrt(x) Returns the square root of x.
int(x) Convert to a 32-bit integer expression.
int32(x) Convert to a 32-bit integer expression.
int64(x) Convert to a 64-bit integer expression.
float(x) Convert to a 64-bit floating point expression.
float32(x) Convert to a 32-bit floating point expression.
float64(x) Convert to a 64-bit floating point expression.
floor(x) The largest integral value that is less than or equal to x.
ceil(x) The smallest integral value that is greater than or equal to x.

Numeric collection functions

min(*exprs) Returns the minimum of a collection or of given numeric expressions.
max(*exprs) Returns the maximum element of a collection or of given numeric expressions.
mean(collection) Returns the mean of all values in the collection.
median(collection) Returns the median value in the collection.
product(collection) Returns the product of values in the collection.
sum(collection) Returns the sum of values in the collection.
argmin(array, unique) Return the index of the minimum value in the array.
argmax(array, unique) Return the index of the maximum value in the array.
hail.expr.functions.abs(x)[source]

Take the absolute value of a numeric value or array.

Examples

>>> hl.abs(-5).value
5
>>> hl.abs([1.0, -2.5, -5.1]).value
[1.0, 2.5, 5.1]
Parameters:x (NumericExpression or ArrayNumericExpression)
Returns:NumericExpression or ArrayNumericExpression.
hail.expr.functions.exp(x) → hail.expr.expressions.typed_expressions.Float64Expression[source]

Computes e raised to the power x.

Examples

>>> hl.exp(2).value
7.38905609893065
Parameters:x (float or Expression of type tfloat64)
Returns:Expression of type tfloat64
hail.expr.functions.is_nan(x) → hail.expr.expressions.typed_expressions.BooleanExpression[source]

Returns True if the argument is NaN (not a number).

Examples

>>> hl.is_nan(0).value
False
>>> hl.is_nan(hl.literal(0) / 0).value
True
>>> hl.is_nan(hl.literal(0) / hl.null(hl.tfloat64)).value
None

Notes

Note that is_missing() will return False on NaN since NaN is a defined value. Additionally, this method will return missing if x is missing.

Parameters:x (float or Expression of type tfloat64) – Expression to test.
Returns:BooleanExpressionTrue if x is NaN, False otherwise.
hail.expr.functions.log(x, base=None) → hail.expr.expressions.typed_expressions.Float64Expression[source]

Take the logarithm of the x with base base.

Examples

>>> hl.log(10).value
2.302585092994046
>>> hl.log(10, 10).value
1.0
>>> hl.log(1024, 2).value
10.0

Notes

If the base argument is not supplied, then the natural logarithm is used.

Parameters:
Returns:

Expression of type tfloat64

hail.expr.functions.log10(x) → hail.expr.expressions.typed_expressions.Float64Expression[source]

Take the logarithm of the x with base 10.

Examples

>>> hl.log10(1000).value
3.0
>>> hl.log10(0.0001123).value
-3.949620243738542
Parameters:x (float or Expression of type tfloat64)
Returns:Expression of type tfloat64
hail.expr.functions.floor(x)[source]

The largest integral value that is less than or equal to x.

Examples

>>> hl.floor(3.1).value
3.0
Parameters:x (Float32Expression or Float64Expression)
Returns:Float32Expression or Float64Expression
hail.expr.functions.ceil(x)[source]

The smallest integral value that is greater than or equal to x.

Examples

>>> hl.ceil(3.1).value
4.0
Parameters:x (Float32Expression or Float64Expression)
Returns:Float32Expression or Float64Expression
hail.expr.functions.sqrt(x) → hail.expr.expressions.typed_expressions.Float64Expression[source]

Returns the square root of x.

Examples

>>> hl.sqrt(3).value
1.7320508075688772

Notes

It is also possible to exponentiate expression with standard Python syntax, e.g. x ** 0.5.

Parameters:x (float or Expression of type tfloat64)
Returns:Expression of type tfloat64
hail.expr.functions.min(*exprs) → hail.expr.expressions.typed_expressions.NumericExpression[source]

Returns the minimum of a collection or of given numeric expressions.

Examples

Take the minimum value of an array:

>>> hl.min([2, 3, 5, 6, 7, 9]).value
2

Take the minimum value:

>>> hl.min(12, 50, 2).value
2

Notes

Like the Python builtin min function, this function can either take a single iterable expression (an array or set of numeric elements), or variable-length arguments of numeric expressions.

Parameters:exprs (ArrayExpression or SetExpression or varargs of NumericExpression) – Single numeric array or set, or multiple numeric values.
Returns:NumericExpression
hail.expr.functions.max(*exprs) → hail.expr.expressions.typed_expressions.NumericExpression[source]

Returns the maximum element of a collection or of given numeric expressions.

Examples

Take the maximum value of an array:

>>> hl.max([1, 3, 5, 6, 7, 9]).value
9

Take the maximum value of values:

>>> hl.max(1, 50, 2).value
50

Notes

Like the Python builtin max function, this function can either take a single iterable expression (an array or set of numeric elements), or variable-length arguments of numeric expressions.

Parameters:exprs (ArrayExpression or SetExpression or varargs of NumericExpression) – Single numeric array or set, or multiple numeric values.
Returns:NumericExpression
hail.expr.functions.mean(collection) → hail.expr.expressions.typed_expressions.Float64Expression[source]

Returns the mean of all values in the collection.

Examples

>>> a = [1, 3, 5, 6, 7, 9]
>>> hl.mean(a).value
5.2

Note

Missing elements are ignored.

Parameters:collection (ArrayExpression or SetExpression) – Collection expression with numeric element type.
Returns:Expression of type tfloat64
hail.expr.functions.median(collection) → hail.expr.expressions.typed_expressions.NumericExpression[source]

Returns the median value in the collection.

Examples

>>> a = [1, 3, 5, 6, 7, 9]
>>> hl.median(a).value
5

Note

Missing elements are ignored.

Parameters:collection (ArrayExpression or SetExpression) – Collection expression with numeric element type.
Returns:NumericExpression
hail.expr.functions.product(collection) → hail.expr.expressions.typed_expressions.NumericExpression[source]

Returns the product of values in the collection.

Examples

>>> a = [1, 3, 5, 6, 7, 9]
>>> hl.product(a).value
5670

Note

Missing elements are ignored.

Parameters:collection (ArrayExpression or SetExpression) – Collection expression with numeric element type.
Returns:NumericExpression
hail.expr.functions.sum(collection) → hail.expr.expressions.typed_expressions.NumericExpression[source]

Returns the sum of values in the collection.

Examples

>>> a = [1, 3, 5, 6, 7, 9]
>>> hl.sum(a).value
31

Note

Missing elements are ignored.

Parameters:collection (ArrayExpression or SetExpression) – Collection expression with numeric element type.
Returns:NumericExpression
hail.expr.functions.argmin(array, unique: bool = False) → hail.expr.expressions.typed_expressions.Int32Expression[source]

Return the index of the minimum value in the array.

Examples

>>> hl.argmin([0.2, 0.3, 0.6]).value
0
>>> hl.argmin([0.4, 0.2, 0.2]).value
1
>>> hl.argmin([0.4, 0.2, 0.2], unique=True).value
None

Notes

Returns the index of the minimum value in the array.

If two or more elements are tied for minimum, then the unique parameter will determine the result. If unique is False, then the first index will be returned. If unique is True, then the result is missing.

If the array is empty, then the result is missing.

Parameters:
Returns:

Expression of type tint32

hail.expr.functions.argmax(array, unique: bool = False) → hail.expr.expressions.typed_expressions.Int32Expression[source]

Return the index of the maximum value in the array.

Examples

>>> hl.argmax([0.2, 0.2, 0.6]).value
2
>>> hl.argmax([0.4, 0.4, 0.2]).value
0
>>> hl.argmax([0.4, 0.4, 0.2], unique=True).value
None

Notes

Returns the index of the maximum value in the array.

If two or more elements are tied for maximum, then the unique parameter will determine the result. If unique is False, then the first index will be returned. If unique is True, then the result is missing.

If the array is empty, then the result is missing.

Parameters:
Returns:

Expression of type tint32