Miscellaneous

pad_jagged_array

spektral.utils.pad_jagged_array(x, target_shape, dtype=<class 'float'>)

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 of varying 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 (note that the creation of the output array may fail if the result is again a jagged array).

  • dtype: the dtype of the returned np.array

Return
A zero-padded np.array of shape (X.shape[0], ) + target_shape


add_eye

spektral.utils.add_eye(x)

Adds the identity matrix to the given matrix.

Arguments

  • x: a rank 2 np.array or scipy.sparse matrix

Return
A rank 2 np.array or scipy.sparse matrix


sub_eye

spektral.utils.sub_eye(x)

Subtracts the identity matrix from the given matrix.

Arguments

  • x: a rank 2 np.array or scipy.sparse matrix

Return
A rank 2 np.array or scipy.sparse matrix


add_eye_batch

spektral.utils.add_eye_batch(x)

Adds the identity matrix to each submatrix of the given rank 3 array.

Arguments

  • x: a rank 3 np.array

Return
A rank 3 np.array


sub_eye_batch

spektral.utils.sub_eye_batch(x)

Subtracts the identity matrix from each submatrix of the given rank 3 array.

Arguments

  • x: a rank 3 np.array

Return
A rank 3 np.array


add_eye_jagged

spektral.utils.add_eye_jagged(x)

Adds the identity matrix to each submatrix of the given rank 3 jagged array.

Arguments

  • x: a rank 3 jagged np.array

Return
A rank 3 jagged np.array


sub_eye_jagged

spektral.utils.sub_eye_jagged(x)

Subtracts the identity matrix from each submatrix of the given rank 3 jagged array.

Arguments

  • x: a rank 3 jagged np.array

Return
A rank 3 jagged np.array