def from_numpy_matrix(cls, mat, variable_order=None, offset=0.0, interactions=None):
        """Create a binary quadratic model from a NumPy array.

        Args:
            mat (:class:`numpy.ndarray`):
                Coefficients of a quadratic unconstrained binary optimization (QUBO)
                model formatted as a square NumPy 2D array.

            variable_order (list, optional):
                If provided, labels the QUBO variables; otherwise, row/column indices are used.
                If `variable_order` is longer than the array, extra values are ignored.

            offset (optional, default=0.0):
                Constant offset for the binary quadratic model.

            interactions (iterable, optional, default=[]):
                Any additional 0.0-bias interactions to be added to the binary quadratic model.

        Returns:
            :class:`.BinaryQuadraticModel`: Binary quadratic model with vartype set to
            :class:`.Vartype.BINARY`.


        Examples:
            This example creates a binary quadratic model from a QUBO in NumPy format while
            adding an interaction with a new variable ('f'), ignoring an extra variable
            ('g'), and setting an offset.

            >>> import dimod
            >>> import numpy as np
            >>> Q = np.array([[1, 0, 0, 10, 11],
            ...               [0, 2, 0, 12, 13],
            ...               [0, 0, 3, 14, 15],
            ...               [0, 0, 0, 4, 0],
            ...               [0, 0, 0, 0, 5]]).astype(np.float32)
            >>> model = dimod.BinaryQuadraticModel.from_numpy_matrix(Q,
            ...         variable_order = ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
            ...         offset = 2.5,
            ...         interactions = {('a', 'f')})
            >>> model.linear   # doctest: +SKIP
            {'a': 1.0, 'b': 2.0, 'c': 3.0, 'd': 4.0, 'e': 5.0, 'f': 0.0}
            >>> model.quadratic[('a', 'd')]
            10.0
            >>> model.quadratic[('a', 'f')]
            0.0
            >>> model.offset
            2.5

        """
        import numpy as np

        if mat.ndim != 2:
            raise ValueError("expected input mat to be a square 2D numpy array")

        num_row, num_col = mat.shape
        if num_col != num_row:
            raise ValueError("expected input mat to be a square 2D numpy array")

        if variable_order is None:
            variable_order = list(range(num_row))

        if interactions is None:
            interactions = []

        bqm = cls({}, {}, offset, Vartype.BINARY)

        for (row, col), bias in np.ndenumerate(mat):
            if row == col:
                bqm.add_variable(variable_order[row], bias)
            elif bias:
                bqm.add_interaction(variable_order[row], variable_order[col], bias)

        for u, v in interactions:
            bqm.add_interaction(u, v, 0.0)

        return bqm
Create a binary quadratic model from a NumPy array.

        Args:
            mat (:class:`numpy.ndarray`):
                Coefficients of a quadratic unconstrained binary optimization (QUBO)
                model formatted as a square NumPy 2D array.

            variable_order (list, optional):
                If provided, labels the QUBO variables; otherwise, row/column indices are used.
                If `variable_order` is longer than the array, extra values are ignored.

            offset (optional, default=0.0):
                Constant offset for the binary quadratic model.

            interactions (iterable, optional, default=[]):
                Any additional 0.0-bias interactions to be added to the binary quadratic model.

        Returns:
            :class:`.BinaryQuadraticModel`: Binary quadratic model with vartype set to
            :class:`.Vartype.BINARY`.


        Examples:
            This example creates a binary quadratic model from a QUBO in NumPy format while
            adding an interaction with a new variable ('f'), ignoring an extra variable
            ('g'), and setting an offset.

            >>> import dimod
            >>> import numpy as np
            >>> Q = np.array([[1, 0, 0, 10, 11],
            ...               [0, 2, 0, 12, 13],
            ...               [0, 0, 3, 14, 15],
            ...               [0, 0, 0, 4, 0],
            ...               [0, 0, 0, 0, 5]]).astype(np.float32)
            >>> model = dimod.BinaryQuadraticModel.from_numpy_matrix(Q,
            ...         variable_order = ['a', 'b', 'c', 'd', 'e', 'f', 'g'],
            ...         offset = 2.5,
            ...         interactions = {('a', 'f')})
            >>> model.linear   # doctest: +SKIP
            {'a': 1.0, 'b': 2.0, 'c': 3.0, 'd': 4.0, 'e': 5.0, 'f': 0.0}
            >>> model.quadratic[('a', 'd')]
            10.0
            >>> model.quadratic[('a', 'f')]
            0.0
            >>> model.offset
            2.5