Vector
Class Vector
(with arithmetic operators)
Vector(v) (v Liste or Tuple)
The Indices of the elements of Vector are counted from 0 (as in Python lists etc.).
Example:
Vector([1,2,3])
Base Class: list
Overview:
Vector (n)
Method | Meaning |
fromFunction (n, fn, offset=0) | Vector, the elements of which are to be calculated using the function fn |
fromString (s) | Vector from String |
Operator | Meaning |
x + y | |
x * y | |
~x | |
x * y | Multiplikation if both operands are vektors sind: inner product, otherwise scalar multiplication (elementwise) |
-x | |
str(x) | |
x - y |
Method | Meaning |
join (y) | Concatenation with Vector w |
norm () | Norm des Vektors v |
operators () | For documentation only |
transp () | berechnet die transponierte Matrix (Spaltenvektor) |
Constructor
Usage: Vector(n)
Vector.fromFunction(n, fn, offset=0)
Usage: Vector.fromFunction(n, fn, offset=0)
Description:
Vector, the elements of which are to be calculated using the function fn
Returns: Vector([fn(i+offset) for i in range(n)])
Example:
Vector.fromFunction(5, sqrt, 1)
returns Vector([1.0, 1.414, 1.732, 2.0, 2.236])
Vector.fromString(s)
Usage: Vector.fromString(s)
Description:
Vector from String
Elements (may also bbe Rationals) must be given as comma separated string.
Example:
Vector.fromString("1, 2/3, 2")
operators + and += (Elementwise addition)
Usage: x + y
Description:
Usage: x * y
Operator ~ (transposition)
Usage: ~x
Description:
Operators * and *=
Usage: x * y
Description:
Multiplikation
if both operands are vektors sind: inner product,
otherwise scalar multiplication (elementwise)
unary oparator - (negative Vektor)
Usage: -x
Description:
Object representation as string
Usage: str(x)
Description:
operators - and -= (elementwise subtraction)
Usage: x - y
Description:
v.join(w)
Usage: x.join(y)
Description:
Concatenation with Vector w
v.norm()
Usage: x.norm()
Description:
Norm des Vektors v
Vector.operators()
Usage: self.operators()
Description:
For documentation only
The following operators are defined in the class Vector:
Op. | Function | Examples |
---|---|---|
+ | elementwise Addition | a + b; a += b |
- | elementwise Subtraction | a - b; a -= b |
* | if both operators are Vectors: inner product, otherwise: scalar multiplication (elementwise) | a * b; a *= b |
- | Unary minus | -a |
[ ] | Index operator | A[i] (Element) |
v.transp()
Usage: v.transp()
Description:
berechnet die transponierte Matrix (Spaltenvektor)
kürzer: ~v