Initializing help system before first use

Products of NumPy arrays

The dot product is a useful operator for carrying out aggregate operations on vectors, matrices, and tensors. The dot operator in NumPy allows for reducing, along one axis of a multi-dimensional arrays, data such as floating points or integer values.

The application of the dot product of NumPy of two multi-dimensional arrays of dimensions (i1, i2, ..., ik') and (j1, j2, ..., jk''), respectively, requires that ik' = jk''-1, i.e., the size of the last dimension of the first array must match the size of the penultimate dimension of the second vector. For instance, the following dot product is valid:

import numpy as np
a = np.random.random (4,6)
b = np.random.random (6,2)
c = np.dot (a,b)

and the result is a 4x2 matrix. The Xpress Python interface has its own dot product operator, which can be used for all similar operations on variables and expression. The rules for applying the Xpress dot operator are the same as for the native Python dot product, with one extra feature: there is no limit on the number of arguments, hence the following example is correct as per the restrictions on the dimensions, albeit it yields a nonconvex constraint.

coeff_pre = np.random.random ((6,3,7))
x = np.array ([xp.var () for i in range(140)]).reshape (4,7,5)
y = np.array ([xp.var () for i in range(80)]).reshape (2,5,8)
coeff_post = np.random.random ((6,8,7))
p.addConstraint (xp.Dot (coeff_pre, x, y, coeff_post) >= 0)

Similar to the NumPy dot product, the Xpress dot product has an out parameter for defining the output in which to store the product.

The following script defines two constraints: the first restricts the squared norm ||z|| = z · z of the vector z of variables to be at most one. It does so by applying the dot operator on the vector itself. The second constraint (t-z)'Q(t-z) ≤ 1 restricts the quadratic form on the left-hand side to be at most 1.

p.addConstraint (xp.Dot (z,z) <= 1) # restrict norm of z to 1

Q = np.random.random (N,N)          # create a random 20x20 matrix
p.addConstraint (xp.Dot ((t-z), Q, (t-z)) <= 1)

As for the Sum operator, when handling variables or expressions, it is advised to use the Dot operator in the Xpress module rather than the native Python operator, for reasons of efficiency.