Vector
Klasse Vector
(mit arithmetischen Operatoren)
Vector(v) (v Liste oder Tupel)
Die Indizes der Elemente von Vector werden (wie in Python-Listen etc.) ab 0 gezählt.
Beispiel:
Vector([1,2,3])
Basisklasse: list
Übersicht:
Vector (n)
Methode | Bedeutung |
fromFunction (n, fn, offset=0) | Vector, dessen Elemente mit der Funktion fn berechnet werden |
fromString (s) | Vector aus String |
Operator | Bedeutung |
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 |
Methode | Bedeutung |
join (y) | Verkettung mit dem Vektor w |
norm () | Norm of the Vector v |
operators () | Nur zur Dokumentation |
transp () | calculates the transposed Matrix (column vektor) |
Konstruktor
Aufruf: Vector(n)
Vector.fromFunction(n, fn, offset=0)
Aufruf: Vector.fromFunction(n, fn, offset=0)
Beschreibung:
Vector, dessen Elemente mit der Funktion fn berechnet werden
Rückgabewert: Vector([fn(i+offset) for i in range(n)])
Beispiel:
Vector.fromFunction(5, sqrt, 1)
ergibt Vector([1.0, 1.414, 1.732, 2.0, 2.236])
Vector.fromString(s)
Aufruf: Vector.fromString(s)
Beschreibung:
Vector aus String
Elemente (auch rationale Zahlen) müssen im String durch Kommas getrennt werden.
Beispiel:
Vector.fromString("1, 2/3, 2")
operators + and += (Elementwise addition)
Aufruf: x + y
Beschreibung:
Aufruf: x * y
Operator ~ (transposition)
Aufruf: ~x
Beschreibung:
Operators * and *=
Aufruf: x * y
Beschreibung:
Multiplikation
if both operands are vektors sind: inner product,
otherwise scalar multiplication (elementwise)
unary oparator - (negative Vektor)
Aufruf: -x
Beschreibung:
Object representation as string
Aufruf: str(x)
Beschreibung:
operators - and -= (elementwise subtraction)
Aufruf: x - y
Beschreibung:
v.join(w)
Aufruf: x.join(y)
Beschreibung:
Verkettung mit dem Vektor w
v.norm()
Aufruf: x.norm()
Beschreibung:
Norm of the Vector v
Vector.operators()
Aufruf: self.operators()
Beschreibung:
Nur zur Dokumentation
Die Klasse Vector erlaubt folgende Operatoren:
Op. | Funktion | Beispiele |
---|---|---|
+ | Elementweise Addition | a + b; a += b |
- | Elementweise Subtraktion | a - b; a -= b |
* | wenn beide Operanden Vektoren sind: Skalarprodukt, sonst Skalarmultiplikation (elementweise) | a * b; a *= b |
- | unäres Minus | -a |
[ ] | Indexoperator | A[i] (Element) |
v.transp()
Aufruf: v.transp()
Beschreibung:
calculates the transposed Matrix (column vektor)
shorter: ~v