

def validate_matrix_shape(name, shape, nrows, ncols, nobs):
    '\n    Validate the shape of a possibly time-varying matrix, or raise an exception\n\n    Parameters\n    ----------\n    name : str\n        The name of the matrix being validated (used in exception messages)\n    shape : array_like\n        The shape of the matrix to be validated. May be of size 2 or (if\n        the matrix is time-varying) 3.\n    nrows : int\n        The expected number of rows.\n    ncols : int\n        The expected number of columns.\n    nobs : int\n        The number of observations (used to validate the last dimension of a\n        time-varying matrix)\n\n    Raises\n    ------\n    ValueError\n        If the matrix is not of the desired shape.\n    '
    ndim = len(shape)
    if (ndim not in [2, 3]):
        raise ValueError(('Invalid value for %s matrix. Requires a 2- or 3-dimensional array, got %d dimensions' % (name, ndim)))
    if (not (shape[0] == nrows)):
        raise ValueError(('Invalid dimensions for %s matrix: requires %d rows, got %d' % (name, nrows, shape[0])))
    if (not (shape[1] == ncols)):
        raise ValueError(('Invalid dimensions for %s matrix: requires %d columns, got %d' % (name, ncols, shape[1])))
    if ((nobs is None) and (not ((ndim == 2) or (shape[(- 1)] == 1)))):
        raise ValueError(('Invalid dimensions for %s matrix: time-varying matrices cannot be given unless `nobs` is specified (implicitly when a dataset is bound or else set explicity)' % name))
    if ((ndim == 3) and (nobs is not None) and (not (shape[(- 1)] in [1, nobs]))):
        raise ValueError(('Invalid dimensions for time-varying %s matrix. Requires shape (*,*,%d), got %s' % (name, nobs, str(shape))))

dataset/ETHPy150Open statsmodels/statsmodels/statsmodels/tsa/statespace/tools.py validate_matrix_shape/original