CyberAtom Python Library

2.5.0

Handling Matrices

Many methods of Device and IResponseHandler classes take arrays (matrices) of floating point values as arguments.

In cyberatom module they are not of standard Python tuples or lists, but of special type from ctype module: ctypes.LP_C_float.

Accessing Elements

When such object is passed from the cyberatom library (e.g. to a IResponse derivced object), elements of the array can be retrievd using typicall [] operator.

For example, when in onFilterProc method:

1 class ResponseHandler(cyberatom.IResponse):
2 
3  def filterProcMatrix(self, mat):
4 
5  # print elements of the received matrix on the console
6  for i in range(0,7):
7  print "Matrix:",mat[i]

Creating Array Objects

For example to create and pass 7-elements array to Device.setFilterProcMatrix() method, that's how it can be achieved:

1 import ctypes
2 
3 ...
4 
5 # Defining 7-elements array type
6 Array7Type = ctypes.c_float * 7
7 
8 # Creating object of that type with initial values
9 mat = Array7Type(2.0 ,2.0 ,2.0 ,2.0, 3.0, 3.0 ,3.0)
10 
11 # Using it in method call
12 device.setFilterProcMatrix(mat)