Hide navigation sidebar
Hide table of contents sidebar
Back to top
Toggle table of contents sidebar

# Matrix-Friendly API Functions

Implements a small set of functions equivalent to numpy that operate on the array-like matrix-friendly API classes `MVar`, `MLinExpr`, `MQuadExpr`, `MConstr`, `MQConstr`, and `MGenConstr`.

hstack(tup)

  Stack arrays in sequence horizontally (column wise). This is equivalent to concatenation along the second axis, except for 1-D arrays where it concatenates along the first axis.

  This method has the same behavior as `numpy.hstack`, except that it always returns a gurobipy matrix-friendly API object of the appropriate type.

  Parameters:

    tup – A sequence of matrix-friendly API objects

  Returns:

    Returns a matrix-friendly API object. Note that the return type depends on the types of the input objects.

  Example:

        X = model.addMVar((k, n))
        Y = model.addMVar((k, m))
        XY = gp.hstack((X, Y))     # (k, n+m) MVar

vstack(tup)

  Stack arrays in sequence vertically (row wise). This is equivalent to concatenation along the first axis after 1-D arrays of shape `(N,)` have been reshaped to `(1,N)`.

  This method has the same behavior as `numpy.vstack`, except that it always returns a gurobipy matrix-friendly API object of the appropriate type.

  Parameters:

    tup – A sequence of matrix-friendly API objects

  Returns:

    Returns a matrix-friendly API object. Note that the return type depends on the types of the input objects.

  Example:

        X = model.addMVar((n, k))
        Y = model.addMVar((m, k))
        XY = gp.vstack((X, Y))     # (n+m, k) MVar

concatenate(tup, axis)

  Join a sequence of arrays along an existing axis.

  This method has the same behavior as `numpy.concatenate`, except that it always returns a gurobipy matrix-friendly API object of the appropriate type.

  Parameters:

    - tup – A sequence of matrix-friendly API objects

    - axis – The axis along which the arrays will be joined. If axis is None, arrays are flattened before use. Default is 0.

  Returns:

    Returns a matrix-friendly API object. Note that the return type depends on the types of the input objects.

  Example:

        X = model.addMVar((k, n))
        Y = model.addMVar((k, m))
        XY = gp.concatenate((X, Y), axis=1)  # (k, n+m) MVar

Help and Feedback

Press `/` or click to search this documentation | Gurobi website | Gurobi community forum
Go to other Gurobi documentation | Gurobi download | Contact support