Beispiel #1
0
 def __add__(self, vectorX):
     '''
     Method to add a vector (of the same size) to the currect vector. 
     The resulting vector will be the result of element-wise addition.
     
     @param vectorX: vector to be added.
     @type vectorX: copads.matrix.Vector object
     @return: resulting copads.matrix.Vector object
     '''
     if len(self.values) != len(vectorX.values):
         raise VectorError('Vectors have different sizes')
     try:
         values = [
             self.values[i] + vectorX.values[i]
             for i in range(len(self.values))
         ]
         return Vector(values)
     except:
         raise VectorError('Failure in Vector.__add__()')
Beispiel #2
0
 def log10(self):
     '''
     Method to perform element-wise log10 on the vector.
     
     @return: result vector as a list.
     '''
     try:
         values = [math.log10(x) for x in self.values]
     except:
         raise VectorError('Failure in Vector.log10()')
     self.values = values
     return self.values
Beispiel #3
0
 def sqrt(self):
     '''
     Method to perform element-wise square root on the vector.
     
     @return: result vector as a list.
     '''
     try:
         values = [math.sqrt(x) for x in self.values]
     except:
         raise VectorError('Failure in Vector.sqrt()')
     self.values = values
     return self.values
Beispiel #4
0
 def acos(self):
     '''
     Method to perform element-wise arc cosine in radians on the vector.
     
     @return: result vector as a list.
     '''
     try:
         values = [math.acos(x) for x in self.values]
     except:
         raise VectorError('Failure in Vector.a()')
     self.values = values
     return self.values
Beispiel #5
0
 def tan(self):
     '''
     Method to perform element-wise tangent in randians on the vector.
     
     @return: result vector as a list.
     '''
     try:
         values = [math.tan(x) for x in self.values]
     except:
         raise VectorError('Failure in Vector.tan()')
     self.values = values
     return self.values
Beispiel #6
0
 def exp(self):
     '''
     Method to perform element-wise exponential (e to the power of the 
     value) on the vector.
     
     @return: result vector as a list.
     '''
     try:
         values = [math.exp(x) for x in self.values]
     except:
         raise VectorError('Failure in Vector.exp()')
     self.values = values
     return self.values
Beispiel #7
0
 def atanh(self):
     '''
     Method to perform element-wise inverse hyperbolic tangent in radians 
     on the vector.
     
     @return: result vector as a list.
     '''
     try:
         values = [math.atanh(x) for x in self.values]
     except:
         raise VectorError('Failure in Vector.atanh()')
     self.values = values
     return self.values
Beispiel #8
0
 def log(self, base=math.e):
     '''
     Method to perform element-wise log on the vector.
     
     @param base: base value of the logarithmic function. Default = e.
     @type base: float
     @return: result vector as a list.
     '''
     base = float(base)
     try:
         values = [math.log(x, base) for x in self.values]
     except:
         raise VectorError('Failure in Vector.log()')
     self.values = values
     return self.values
Beispiel #9
0
 def root(self, n):
     '''
     Method to perform element-wise n-th root on the vector.
     
     @param n: value of the root.
     @type n: float
     @return: result vector as a list.
     '''
     n = float(n)
     try:
         values = [float(x)**(1.0 / float(n)) for x in self.values]
     except:
         raise VectorError('Failure in Vector.root()')
     self.values = values
     return self.values
Beispiel #10
0
 def pow(self, n):
     '''
     Method to perform element-wise power (value to the power of n) on 
     the vector.
     
     @param n: exponent to be raised.
     @type n: float
     @return: result vector as a list.
     '''
     n = float(n)
     try:
         values = [float(x)**n for x in self.values]
     except:
         raise VectorError('Failure in Vector.pow()')
     self.values = values
     return self.values