

def matdims(arr, oned_as='column'):
    '\n    Determine equivalent MATLAB dimensions for given array\n\n    Parameters\n    ----------\n    arr : ndarray\n        Input array\n    oned_as : {\'column\', \'row\'}, optional\n        Whether 1-D arrays are returned as MATLAB row or column matrices.\n        Default is \'column\'.\n\n    Returns\n    -------\n    dims : tuple\n        Shape tuple, in the form MATLAB expects it.\n\n    Notes\n    -----\n    We had to decide what shape a 1 dimensional array would be by\n    default.  ``np.atleast_2d`` thinks it is a row vector.  The\n    default for a vector in MATLAB (e.g. ``>> 1:12``) is a row vector.\n\n    Versions of scipy up to and including 0.11 resulted (accidentally)\n    in 1-D arrays being read as column vectors.  For the moment, we\n    maintain the same tradition here.\n\n    Examples\n    --------\n    >>> matdims(np.array(1)) # numpy scalar\n    (1, 1)\n    >>> matdims(np.array([1])) # 1d array, 1 element\n    (1, 1)\n    >>> matdims(np.array([1,2])) # 1d array, 2 elements\n    (2, 1)\n    >>> matdims(np.array([[2],[3]])) # 2d array, column vector\n    (2, 1)\n    >>> matdims(np.array([[2,3]])) # 2d array, row vector\n    (1, 2)\n    >>> matdims(np.array([[[2,3]]])) # 3d array, rowish vector\n    (1, 1, 2)\n    >>> matdims(np.array([])) # empty 1d array\n    (0, 0)\n    >>> matdims(np.array([[]])) # empty 2d\n    (0, 0)\n    >>> matdims(np.array([[[]]])) # empty 3d\n    (0, 0, 0)\n\n    Optional argument flips 1-D shape behavior.\n\n    >>> matdims(np.array([1,2]), \'row\') # 1d array, 2 elements\n    (1, 2)\n\n    The argument has to make sense though\n\n    >>> matdims(np.array([1,2]), \'bizarre\')\n    Traceback (most recent call last):\n       ...\n    ValueError: 1D option "bizarre" is strange\n\n    '
    shape = arr.shape
    if (shape == ()):
        return (1, 1)
    if (reduce(operator.mul, shape) == 0):
        return ((0,) * np.max([arr.ndim, 2]))
    if (len(shape) == 1):
        if (oned_as == 'column'):
            return (shape + (1,))
        elif (oned_as == 'row'):
            return ((1,) + shape)
        else:
            raise ValueError(('1D option "%s" is strange' % oned_as))
    return shape

dataset/ETHPy150Open scipy/scipy/scipy/io/matlab/miobase.py matdims/original