Biogeme: Python Library  4.6a
bioMatrix.py
Go to the documentation of this file.
1 
5 
6 
8 class bioMatrix(object):
9 
20  def __init__(self, dim, names, values):
21 
22  self.dim = dim
23  self.names = names
24  j = 0
25  self.keys = {}
26  for i in names:
27  self.keys[i] = j
28  j += 1
29  # initialize matrix and fill with zeroes
30  self.matrix = []
31  for i in names:
32  ea_row = []
33  for j in range(dim):
34  ea_row.append(values[self.keys[i]][j])
35  self.matrix.append(ea_row)
36 
37 
43  def setvalue(self, rowname, colname, v):
44  self.matrix[self.keys[colname]][self.keys[rowname]] = v
45  self.matrix[self.keys[rowname]][self.keys[colname]] = v
46 
47 
51  def getvalue(self, rowname, colname):
52  return self.matrix[self.keys[colname]][self.keys[rowname]]
53 
54 
55  def __str__(self):
56  outStr = ""
57  for k in self.names:
58  outStr += '%s: %s\n' % (k,self.matrix[self.keys[k]])
59  return outStr
def setvalue(self, rowname, colname, v)
Set an entry of the matrix.
Definition: bioMatrix.py:43
This class implements a matrix object designed to store the variance covariance matrix.
Definition: bioMatrix.py:8
def __str__(self)
Function called by the print statement.
Definition: bioMatrix.py:55
def getvalue(self, rowname, colname)
Get an entry of the matrix.
Definition: bioMatrix.py:51
def __init__(self, dim, names, values)
Constructor.
Definition: bioMatrix.py:20
dim
Dimension of the (square) matrix.
Definition: bioMatrix.py:22
Copyright 2017 Michel Bierlaire