array

mdtools.check.array(a, shape=None, dim=None, axis=None, amin=None, amax=None, dtype=None)[source]

Check if the input array satisfies the given conditions.

The array must meet the following requirements:

  • Must be of an array_like type, i.e. a type that can be converted to a numpy.ndarray.

  • Must have a shape equal to the supplied shape.

  • Must have a dimension equal to the supplied dim.

  • Must contain the supplied axis.

  • All array elements must be greater than or equal to amin (if supplied).

  • All array elements must be less than or equal to amax (if supplied).

  • Must have a data type equal to the supplied dtype.

Parameters:
  • a (array_like) – The array to check.

  • shape (tuple, optional) – The shape expected for a. Default is None, which means that the shape of a is not checked.

  • dim (int, optional) – The dimension expected for a. Default is None, which means that the dimension of a is not checked.

  • axis (int, optional) – Index of an axis that should be contained in a. Default is None, which means that it is not checked whether a contains the given axis.

  • amin (scalar or array_like) – Minimum values that the elements of a must not undermine. If amin and a do not have the same shape, they must be broadcastable to a common shape.

  • amax (scalar or array_like) – Maximum values that the elements of a must not exceed. If amax and a do not have the same shape, they must be broadcastable to a common shape. amax must be greater than amin.

  • dtype (type, optional) – The data type expected for a. Default is None, which means that the data type of a is not checked.

Returns:

a (numpy.ndarray) – The input array as numpy.ndarray.

Raises:
  • ValueError – If shape is not None and the shape of a is not shape; dim is not None and the dimension of a is not dim; a contains elements that are less than amin; a contains elements that are greater than amax; Or if the given combination of shape, dim and axis is invalid; amax is less than amin.

  • numpy.exceptions.AxisError – If axis is not None and the axis is out of bounds for a.

  • TypeError – If dtype is not None and the data type of a is not dtype.

  • RuntimeError – If all arguments (except a) are None.

See also

mdtools.check.pos_array()

Check if an array is a suitable position array

mdtools.check.box()

Check if an array is a suitable simulation box array

mdtools.check.dtrj()

Check if an array is a suitable discrete trajectory array