(cls, *args, **kwargs)
return rows, cols, flat_list
Return the number of rows, cols and flat matrix elements.

        Examples
        ========

        >>> from sympy import Matrix, I

        Matrix can be constructed as follows:

        * from a nested list of iterables

        >>> Matrix( ((1, 2+I), (3, 4)) )
        Matrix([
        [1, 2 + I],
        [3,     4]])

        * from un-nested iterable (interpreted as a column)

        >>> Matrix( [1, 2] )
        Matrix([
        [1],
        [2]])

        * from un-nested iterable with dimensions

        >>> Matrix(1, 2, [1, 2] )
        Matrix([[1, 2]])

        * from no arguments (a 0 x 0 matrix)

        >>> Matrix()
        Matrix(0, 0, [])

        * from a rule

        >>> Matrix(2, 2, lambda i, j: i/(j + 1) )
        Matrix([
        [0,   0],
        [1, 1/2]])
Return the number of rows, cols and flat matrix elements.
Return the number of rows cols and flat matrix elements .
def _handle_creation_inputs(cls, *args, **kwargs):
        """Return the number of rows, cols and flat matrix elements.

        Examples
        ========

        >>> from sympy import Matrix, I

        Matrix can be constructed as follows:

        * from a nested list of iterables

        >>> Matrix( ((1, 2+I), (3, 4)) )
        Matrix([
        [1, 2 + I],
        [3,     4]])

        * from un-nested iterable (interpreted as a column)

        >>> Matrix( [1, 2] )
        Matrix([
        [1],
        [2]])

        * from un-nested iterable with dimensions

        >>> Matrix(1, 2, [1, 2] )
        Matrix([[1, 2]])

        * from no arguments (a 0 x 0 matrix)

        >>> Matrix()
        Matrix(0, 0, [])

        * from a rule

        >>> Matrix(2, 2, lambda i, j: i/(j + 1) )
        Matrix([
        [0,   0],
        [1, 1/2]])

        """
        from sympy.matrices.sparse import SparseMatrix

        # Matrix(SparseMatrix(...))
        if len(args) == 1 and isinstance(args[0], SparseMatrix):
            return args[0].rows, args[0].cols, flatten(args[0].tolist())

        # Matrix(Matrix(...))
        if len(args) == 1 and isinstance(args[0], MatrixBase):
            return args[0].rows, args[0].cols, args[0]._mat

        # Matrix(MatrixSymbol('X', 2, 2))
        if len(args) == 1 and isinstance(args[0], Basic) and args[0].is_Matrix:
            return args[0].rows, args[0].cols, args[0].as_explicit()._mat

        if len(args) == 3:
            rows = as_int(args[0])
            cols = as_int(args[1])

        # Matrix(2, 2, lambda i, j: i+j)
        if len(args) == 3 and isinstance(args[2], collections.Callable):
            operation = args[2]
            flat_list = []
            for i in range(rows):
                flat_list.extend([cls._sympify(operation(cls._sympify(i), j))
                    for j in range(cols)])

        # Matrix(2, 2, [1, 2, 3, 4])
        elif len(args) == 3 and is_sequence(args[2]):
            flat_list = args[2]
            if len(flat_list) != rows*cols:
                raise ValueError('List length should be equal to rows*columns')
            flat_list = [cls._sympify(i) for i in flat_list]

        # Matrix(numpy.ones((2, 2)))
        elif len(args) == 1 and hasattr(args[0], "__array__"):  # pragma: no cover
            # NumPy array or matrix or some other object that implements
            # __array__. So let's first use this method to get a
            # numpy.array() and then make a python list out of it.
            arr = args[0].__array__()
            if len(arr.shape) == 2:
                rows, cols = arr.shape[0], arr.shape[1]
                flat_list = [cls._sympify(i) for i in arr.ravel()]
                return rows, cols, flat_list
            elif len(arr.shape) == 1:
                rows, cols = 1, arr.shape[0]
                flat_list = [S.Zero]*cols
                for i in range(len(arr)):
                    flat_list[i] = cls._sympify(arr[i])
                return rows, cols, flat_list
            else:
                raise NotImplementedError(
                    "SymPy supports just 1D and 2D matrices")

        # Matrix([1, 2, 3]) or Matrix([[1, 2], [3, 4]])
        elif len(args) == 1 and is_sequence(args[0])\
                and not isinstance(args[0], DeferredVector):
            in_mat = []
            ncol = set()
            for row in args[0]:
                if isinstance(row, MatrixBase):
                    in_mat.extend(row.tolist())
                    if row.cols or row.rows:  # only pay attention if it's not 0x0
                        ncol.add(row.cols)
                else:
                    in_mat.append(row)
                    try:
                        ncol.add(len(row))
                    except TypeError:
                        ncol.add(1)
            if len(ncol) > 1:
                raise ValueError("Got rows of variable lengths: %s" %
                    sorted(list(ncol)))
            cols = ncol.pop() if ncol else 0
            rows = len(in_mat) if cols else 0
            if rows:
                if not is_sequence(in_mat[0]):
                    cols = 1
                    flat_list = [cls._sympify(i) for i in in_mat]
                    return rows, cols, flat_list
            flat_list = []
            for j in range(rows):
                for i in range(cols):
                    flat_list.append(cls._sympify(in_mat[j][i]))

        # Matrix()
        elif len(args) == 0:
            # Empty Matrix
            rows = cols = 0
            flat_list = []

        else:
            raise TypeError("Data type not understood")

        return rows, cols, flat_list
def _handle_creation_inputs ( cls , * args , * * kwargs ) : from sympy . matrices . sparse import SparseMatrix # Matrix(SparseMatrix(...)) if len ( args ) == 1 and isinstance ( args [ 0 ] , SparseMatrix ) : return args [ 0 ] . rows , args [ 0 ] . cols , flatten ( args [ 0 ] . tolist ( ) ) # Matrix(Matrix(...)) if len ( args ) == 1 and isinstance ( args [ 0 ] , MatrixBase ) : return args [ 0 ] . rows , args [ 0 ] . cols , args [ 0 ] . _mat # Matrix(MatrixSymbol('X', 2, 2)) if len ( args ) == 1 and isinstance ( args [ 0 ] , Basic ) and args [ 0 ] . is_Matrix : return args [ 0 ] . rows , args [ 0 ] . cols , args [ 0 ] . as_explicit ( ) . _mat if len ( args ) == 3 : rows = as_int ( args [ 0 ] ) cols = as_int ( args [ 1 ] ) # Matrix(2, 2, lambda i, j: i+j) if len ( args ) == 3 and isinstance ( args [ 2 ] , collections . Callable ) : operation = args [ 2 ] flat_list = [ ] for i in range ( rows ) : flat_list . extend ( [ cls . _sympify ( operation ( cls . _sympify ( i ) , j ) ) for j in range ( cols ) ] ) # Matrix(2, 2, [1, 2, 3, 4]) elif len ( args ) == 3 and is_sequence ( args [ 2 ] ) : flat_list = args [ 2 ] if len ( flat_list ) != rows * cols : raise ValueError ( 'List length should be equal to rows*columns' ) flat_list = [ cls . _sympify ( i ) for i in flat_list ] # Matrix(numpy.ones((2, 2))) elif len ( args ) == 1 and hasattr ( args [ 0 ] , "__array__" ) : # pragma: no cover # NumPy array or matrix or some other object that implements # __array__. So let's first use this method to get a # numpy.array() and then make a python list out of it. arr = args [ 0 ] . __array__ ( ) if len ( arr . shape ) == 2 : rows , cols = arr . shape [ 0 ] , arr . shape [ 1 ] flat_list = [ cls . _sympify ( i ) for i in arr . ravel ( ) ] return rows , cols , flat_list elif len ( arr . shape ) == 1 : rows , cols = 1 , arr . shape [ 0 ] flat_list = [ S . Zero ] * cols for i in range ( len ( arr ) ) : flat_list [ i ] = cls . _sympify ( arr [ i ] ) return rows , cols , flat_list else : raise NotImplementedError ( "SymPy supports just 1D and 2D matrices" ) # Matrix([1, 2, 3]) or Matrix([[1, 2], [3, 4]]) elif len ( args ) == 1 and is_sequence ( args [ 0 ] ) and not isinstance ( args [ 0 ] , DeferredVector ) : in_mat = [ ] ncol = set ( ) for row in args [ 0 ] : if isinstance ( row , MatrixBase ) : in_mat . extend ( row . tolist ( ) ) if row . cols or row . rows : # only pay attention if it's not 0x0 ncol . add ( row . cols ) else : in_mat . append ( row ) try : ncol . add ( len ( row ) ) except TypeError : ncol . add ( 1 ) if len ( ncol ) > 1 : raise ValueError ( "Got rows of variable lengths: %s" % sorted ( list ( ncol ) ) ) cols = ncol . pop ( ) if ncol else 0 rows = len ( in_mat ) if cols else 0 if rows : if not is_sequence ( in_mat [ 0 ] ) : cols = 1 flat_list = [ cls . _sympify ( i ) for i in in_mat ] return rows , cols , flat_list flat_list = [ ] for j in range ( rows ) : for i in range ( cols ) : flat_list . append ( cls . _sympify ( in_mat [ j ] [ i ] ) ) # Matrix() elif len ( args ) == 0 : # Empty Matrix rows = cols = 0 flat_list = [ ] else : raise TypeError ( "Data type not understood" ) return rows , cols , flat_list