survive.utils.check_data_2d

survive.utils.check_data_2d(data, *, numeric=True, n_exact=None, n_min=None, n_max=None, p_exact=None, p_min=None, p_max=None, keep_pandas=True, copy=False, dtype=None, order=None)[source]

Preprocess and validate a two-dimensional array (i.e., a matrix).

A matrix of shape (n, p) represents n observations of p features. That is, each of the n rows represents the p features of a single observation, and likewise each of the p columns represents all n observations of a single feature.

If data is a scalar, it is interpreted as one observation of one feature and is coerced into a NumPy array of shape (1, 1).

If data is an array of shape (n, ), then it is interpreted as n observations of a single feature and is coerced into a NumPy array of shape (n, 1). This means that if you want one observation of p features, then you must pass in a two-dimensional array of shape (1, p).

Parameters:
data : array-like

Matrix of shape (n, p) (n=number of observations, p=number of features).

numeric : bool, optional

If True, ensure that the entries in the array are of a numeric type.

n_exact : int, optional

Exact number of observations (rows) expected.

n_min : int, optional

Minimum number of observations (rows) expected.

n_max : int, optional

Maximum number of observations (rows) expected.

p_exact : int, optional

Exact number of features (columns) expected.

p_min : int, optional

Minimum number of features (columns) expected.

p_max : int, optional

Maximum number of features (columns) expected.

keep_pandas : bool, optional

If True, keep a pandas.DataFrame as a DataFrame instead of converting it to a numpy.ndarray.

copy : bool, optional

If True, the array will be copied. If False, the array might be copied depending on the behavior of numpy.array().

dtype : str or type, optional (default: None)

The desired data type of the validated array.

order : str, optional (default: None)

The desired memory layout of the array. See the numpy.array() documentation for details.

Returns:
data : two-dimensional numpy.ndarray or pandas.DataFrame

The validated two-dimensional array.

Raises:
ValueError

If the input array is empty or is has more than two dimensions, or if any of the optional constraints on the data type or the number of rows and columns is violated.