match_shape

mdtools.numpy_helper_functions.match_shape(a, b, fill_value=0, transfer_to_new_dim=True)[source]

Bring two arrays to the same shape by padding a given value at the end of of the axes of the shorter array.

Parameters:
  • a, b (array_like) – The arrays to bring to the same shape.

  • fill_value (scalar, optional) – The fill value to use if the arrays must be extended in one or more dimensions to get them to the same shape. Note that you might have to change the data type of the input arrays to fit the type of fill_value before parsing them to this function.

  • transfer_to_new_dim (bool, optional) – If a new dimension needs to be added to one of the arrays, transfer the values of the original array also to this new dimension. Default: True

Returns:

a_new, b_new (numpy.ndarray) – Copies of the input arrays padded with fill_value in such a way that they have the same shape. If a and b already had the same shape, just the input arrays are returned.