UserManual

vector

Module vector provides class Vector, function and some exception.

CLASSES

Module vector provides classes as follows.

class Vector

Class Vector is an elemental class of vector.

Initialize
>>> aVector=Vector(list)
Variable aVector initializes to Vector object.
Example to use:
>>> u=Vector([0,1,3])
>>> v=Vector([2,1,2])
>>> z=Vector([0]*3)
>>> z
Vector [0, 0, 0]
Operators
Class Vector provides operators and methods as follows.
  • "+", "-"
    addition and subtraction.
    operate with two vector of same length, or return Exception VectorSizeError.
    >>> u+v
    Vector [2, 2, 5]
    >>> -u
    Vector [0, -1, -3]
  • "*", "/"
    scalar product.
    >>> v*3
    Vector [6, 3, 6]
  • len(aVector)
    return length of aVector.
    >>> len(u)
    3
  • repr(aVector)
    return representation string of aVector.
    >>> repr(u)
    'Vector [0, 1, 3]'
  • str(aVector)
    return string of listed representation of aVector.
    >>> str(u)
    '[0, 1, 3]'
Function
Class Vector defined functions as follows.
  • aVector.copy()
    return a copy of aVector.
    >>> x=u.copy()
    >>> x
    Vector [0, 1, 3]
  • aVector.set(list)
    substitute aVector with list.
    >>> x.set([2,1])
    >>> x
    Vector [2, 1]
  • aVector.indexOfNoneZero()
    return nonzero index of aVector. if aVector is zero vector, return exception.
    >>> u.indexOfNoneZero()
    2
    >>> x.indexOfNoneZero()
    1
    >>> z.indexOfNoneZero()
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File "vector.py", line 94, in indexOfNoneZero
        raise Exception, "all zero"
    Exception: all zero

class VectorSizeError

Class VectorSizeError defines Exception VectorSizeError.

FUNCTIONS

Module vector provides functions as follows.

def innerProduct(aVector, other)

return innerProduct.

>>> innerProduct(u,v)
7

EXCEPTIONS

Module vector provide exceptions as follows.

except VectorSizeError

Exception VectorSizeError occurs additive operation with two vector of different length.

>>> u=Vector([0,1,3])
>>> w=Vector([4,3,2,0])
>>> u+w
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "vector.py", line 31, in __add__
    raise VectorSizeError
VectorSizeError

DEPENDENCY

This module can be used independently of other NZMATH modules.

BUGS(IMPLEMENT PROBLEMS, MAYBE)

Implementation of InnerProduct

innerProduct with imaginary module are not implemented.


Last-modified: 2006-03-05 (Æü) 20:23:54