Example script for Python interface to Orthogonal Array package

Pieter Eendebak pieter.eendebak@gmail.com

[1]:
import numpy as np

import oapackage

print("oapackage version: %s" % oapackage.version())
oapackage version: 2.6.0

Load an example array.

[2]:
array = oapackage.exampleArray(0)
array.showarray()
array:
  0   0
  0   0
  0   1
  0   1
  1   0
  1   0
  1   1
  1   1

Calculate properties of the array such as the D-efficiency for the main effects model, the generalized word length pattern and the rank.

[3]:
print("D-efficiency %f, rank %d" % (array.Defficiency(), array.rank()))
print("Generalized wordlength pattern: %s" % str(array.GWLP()))
D-efficiency 1.000000, rank 2
Generalized wordlength pattern: (1.0, 0.0, 0.0)

Calculate the generalized word length pattern for another example array.

[11]:
array = oapackage.exampleArray(11)
print("Generalized wordlength pattern: %s" % oapackage.oahelper.gwlp2str(array.GWLP()))
Generalized wordlength pattern: 1.00,0.02273,0.03926,0.5434,0.8244,2.217,1.043,0.126,0.002066

Indexing

The array_link object can be indexed as a normal array.

[12]:
array[0:5, 2:3]
[12]:
array_link: 5, 1
[14]:
array[0:5, 2:4].showarray()
array:
  1   1
  0   1
  1   0
  0   0
  1   1
[15]:
print(array[0, 2])
1

Numpy

We can convert between Numpy arrays and array_link objects. Note that an array_link is always integer valued.

[19]:
X = (4 * np.random.rand(20, 10)).astype(int)
array = oapackage.array_link(X)
array.showarraycompact()
2003200102
0322120001
3030110033
0311131120
2200100200
2112333121
3110300211
3302313313
2331031302
1212232322
3003330322
0312311331
3222200313
2001123302
2222111302
0020322112
0101223211
0223300100
1232030100
0320032113

Convert from array_link back to Numpy array.

[20]:
X2 = np.array(array)