25.11.2015 Views

The MOSEK Python optimizer API manual Version 7.0 (Revision 141)

Optimizer API for Python - Documentation - Mosek

Optimizer API for Python - Documentation - Mosek

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

5.13. CONVENTIONS EMPLOYED IN THE <strong>API</strong> 75<br />

5.13.4 Array objects<br />

<strong>The</strong> <strong>MOSEK</strong> <strong>Python</strong> <strong>API</strong> provides a simple array object in the module mosekarr. This includes a<br />

one-dimensional dense array which can be of type Float, Int or Object, and a few operators and<br />

functions to create and modify array objects.<br />

Arrays can be constructed in several ways:<br />

# Create an array of integers<br />

a0 = array([1,2,3],int)<br />

# Create an array of floats<br />

a1 = array([1,2,3],float)<br />

# Create an integer array of ones<br />

a2 = ones(10)<br />

# Create an float array of ones<br />

a3 = ones(10,float)<br />

# Create a range of integers 5,6,...,9<br />

a4 = range(5,10)<br />

# Create and array of objects<br />

a5 = array([’a string’, ’b string’, 10, 2.2])<br />

A limited set of operations on arrays are available - these should work more or less like the equivalent<br />

Numeric operations:<br />

a = ones(10,float)<br />

b = 1.0 * arange(10)<br />

# element-wise multiplication, addition and subtraction<br />

c0 = a * b<br />

c1 = a + b<br />

c2 = a - b<br />

# multiplly each element by 2.1<br />

c4 = a * 2.1<br />

# add 2 to each element<br />

c5 = a + 2<br />

If more advanced array operations is needed, it is necessary to install the <strong>Python</strong> Numeric package.<br />

5.13.5 Typical problems using the <strong>Python</strong> <strong>API</strong><br />

Since all all type-information in <strong>Python</strong> is implicit, type-checking is performed only when required,<br />

and in certain cases it is necessary to explicitly write type information.<br />

<strong>The</strong> <strong>MOSEK</strong> <strong>API</strong> currently only supports its own array object (mosek.array.array) and <strong>Python</strong>numpy<br />

arrays. Other array or list compatible objects will are accepted but are converted.<br />

Typically type errors occur in two situations:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!