xpress.Dot
Alternative dot-product operator for an arbitrary number of NumPy single- or multi-dimensional arrays. Following the convention for dot-product, the result of Dot for a list of k objects T1, T2, ..., Tk of d1, d2, ..., dk dimensions is an object of d1 + d2 + ... + dk - 2(k-1) dimensions. For each i-th factor in [1,2,...,k-1], the arity of the last dimension of Ti must match the arity of the penultimate dimension of Ti+1 (or its arity if Ti+1 is single-dimensional, i.e., a vector).
a = xpress.Dot(t1, t2, ..., out)
out
|
(optional) NumPy array of the correct dimension and arity where the result is stored. If not provided, the dot product is returned.
|
import numpy as np import xpress as xp N = 10 M = 20 S = range(N) p = xp.problem() x = np.array([p.addVariable() for i in S], dtype=xp.npvar) x0 = np.random.random(N) # creates an N-vector of random numbers # objective function is the squared Euclidean distance of the # variable vector x from a fixed point x0 p.setObjective(xp.Dot((x-x0),(x-x0))) A = np.random.random((M,N)) b = np.random.random(M) # constraint Ax = b, random MxN matrix A and M-vector b p.addConstraint(xp.Dot(A, x) == b) # Create a single quadratic constraint with # a positive semidefinite matrix Q + N^3 * I Q = np.random.random((N,N)) p.addConstraint(xp.Dot(x, Q + N**3 * np.eye(N), x) <= 1) # Create four quadratic constraints using an order-three # tensor, i.e., a three-dimensional array. k = 4 T = np.random.random((k,N,N)) q = np.random.random(k) p.addConstraint(xp.Dot(x, T, x) <= q)
result = T[0] for i in range(1,k): result = xpress.Dot(result, T[i])
The dot product of two multi-dimensional array T' and T'' of dimensions d' and d'' and of arities (n1, n2, ..., nd') and (m1, m2, ..., md''), respectively, is a multi-dimensional array of dimension d' + d'' - 2, whose arity vector is (n1, n2, ..., nd'-1, m1, m2, ..., md''-2, md'') and whose generic element is
vi1,i2,...,id'-1, j1,j2,...,jd''-2,jd'' = ∑1≤h≤nd' t'i1,i2,...,id'-1,h· t''j1,j2,...,jd''-2,h,jd''.
It is assumed here that nd' = md''-1. Two simple cases may help understand the behavior of the operator: for two single-dimensional arrays v' and v'' of size n, the result is the inner product
∑1≤h≤n v'h· v''h.
For two matrices A and B of sizes m×n and n×p respectively, the result is the m×p matrix C whose generic element is
Cij = ∑1≤h≤n Aih· Bhj.
x = p.addVariables(1000) A = scipy.sparse.csr_array(scipy.sparse.random(1000, 1000, density=0.1)) b = np.random.random(1000) p.addConstraint(xp.Dot(A, x) <= b)
xpress.Dot can compute the product of a 1-dimensional NumPy array of variables or expressions with a sparse matrix of type int32, int64, float32 or float64 in CSR or CSC format. Computing the product of an N-dimensional array with a sparse matrix is not currently supported when N > 1.
See https://docs.scipy.org/doc/scipy/reference/sparse.html for more information about SciPy sparse matrices.
© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.