nd

NDArray Functions

Notes

This is a recently added, experimental module. We would love to hear what use cases you have for this as we expand this functionality

array(input_array) Construct an NDArrayExpression
arange(start[, stop, step]) Returns a 1-dimensions ndarray of integers from start to stop by step.
full(shape, value[, dtype]) Creates a hail NDArrayNumericExpression full of the specified value.
zeros(shape[, dtype]) Creates a hail NDArrayNumericExpression full of zeros.
ones(shape[, dtype]) Creates a hail NDArrayNumericExpression full of ones.
qr(nd[, mode]) Performs a QR decomposition.
hail.nd.array(input_array)[source]

Construct an NDArrayExpression

Examples

>>> hl.eval(hl.nd.array([1, 2, 3, 4]))
array([1, 2, 3, 4], dtype=int32)
>>> hl.eval(hl.nd.array([[1, 2, 3], [4, 5, 6]]))
array([[1, 2, 3],
   [4, 5, 6]], dtype=int32)
>>> hl.eval(hl.nd.array(np.identity(3)))
array([[1., 0., 0.],
   [0., 1., 0.],
   [0., 0., 1.]])
>>> hl.eval(hl.nd.array(hl.range(10, 20)))
array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19], dtype=int32)
Parameters:input_array (ArrayExpression or numpy ndarray or nested python lists)
Returns:NDArrayExpression – An ndarray based on the input array.
hail.nd.arange(start, stop=None, step=1) → hail.expr.expressions.typed_expressions.NDArrayNumericExpression[source]

Returns a 1-dimensions ndarray of integers from start to stop by step.

Examples

>>> hl.eval(hl.nd.arange(10))
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], dtype=int32)
>>> hl.eval(hl.nd.arange(3, 10))
array([3, 4, 5, 6, 7, 8, 9], dtype=int32)
>>> hl.eval(hl.nd.arange(0, 10, step=3))
array([0, 3, 6, 9], dtype=int32)

Notes

The range includes start, but excludes stop.

If provided exactly one argument, the argument is interpreted as stop and start is set to zero. This matches the behavior of Python’s range.

Parameters:
Returns:

NDArrayNumericExpression – A 1-dimensional ndarray from start to stop by step.

hail.nd.full(shape, value, dtype=None)[source]

Creates a hail NDArrayNumericExpression full of the specified value.

Examples

Create a 5 by 7 NDArray of type tfloat64 9s.

>>> hl.nd.full((5, 7), 9)

It is possible to specify a type other than tfloat64 with the dtype argument.

>>> hl.nd.full((5, 7), 9, dtype=hl.tint32)
Parameters:
Returns:

NDArrayNumericExpression – An ndarray of the specified shape filled with the specified value.

hail.nd.zeros(shape, dtype=dtype('float64'))[source]

Creates a hail NDArrayNumericExpression full of zeros.

Examples

Create a 5 by 7 NDArray of type tfloat64 zeros.

>>> hl.nd.zeros((5, 7))

It is possible to specify a type other than tfloat64 with the dtype argument.

>>> hl.nd.zeros((5, 7), dtype=hl.tfloat32)
Parameters:

See also

full()

Returns:NDArrayNumericExpression – ndarray of the specified size full of zeros.
hail.nd.ones(shape, dtype=dtype('float64'))[source]

Creates a hail NDArrayNumericExpression full of ones.

Examples

Create a 5 by 7 NDArray of type tfloat64 ones.

>>> hl.nd.ones((5, 7))

It is possible to specify a type other than tfloat64 with the dtype argument.

>>> hl.nd.ones((5, 7), dtype=hl.tfloat32)
Parameters:

See also

full()

Returns:NDArrayNumericExpression – ndarray of the specified size full of ones.
hail.nd.qr(nd, mode='reduced')[source]

Performs a QR decomposition.

Parameters:
  • nd – A 2 dimensional ndarray, shape(M, N)
  • mode

    One of “reduced”, “complete”, “r”, or “raw”.

    If K = min(M, N), then:

    • reduced: returns q and r with dimensions (M, K), (K, N)
    • complete: returns q and r with dimensions (M, M), (M, N)
    • r: returns only r with dimensions (K, N)
    • raw: returns h, tau with dimensions (N, M), (K,)
Returns:

  • - q (ndarray of float64) – A matrix with orthonormal columns.
  • - r (ndarray of float64) – The upper-triangular matrix R.
  • - (h, tau) (ndarrays of float64) – The array h contains the Householder reflectors that generate q along with r. The tau array contains scaling factors for the reflectors