Miscellaneous

pad_jagged_array

spektral.utils.pad_jagged_array(x, target_shape)

Given a jagged array of arbitrary dimensions, zero-pads all elements in the array to match the provided target_shape.

Arguments

  • x: a list or np.array of dtype object, containing np.arrays with variable dimensions;

  • target_shape: a tuple or list s.t. target_shape[i] >= x.shape[i] for each x in X. If target_shape[i] = -1, it will be automatically converted to X.shape[i], so that passing a target shape of e.g. (-1, n, m) will leave the first dimension of each element untouched.

Return
A np.array of shape (len(x), ) + target_shape.


one_hot

spektral.utils.one_hot(x, depth)

One-hot encodes the integer array x in an array of length depth.

Arguments

  • x: a np.array of integers.

  • depth: size of the one-hot vectors.

Return
An array of shape x.shape + (depth, )


label_to_one_hot

spektral.utils.label_to_one_hot(x, labels)

One-hot encodes the integer array x according to the given labels.

Arguments

  • x: a np.array of integers. Each value must be contained in labels.

  • labels: list/tuple/np.array of labels.

Return
An array of shape x.shape + (len(labels), )


flatten_list

spektral.utils.flatten_list(alist)

Flattens an arbitrarily nested list to 1D.

Arguments

  • alist: a list or np.array (with at least one dimension), arbitrarily nested.

Return
A 1D Python list with the flattened elements as returned by a depth-first search.