Ruby/Справочник/Vector
Класс VectorПравить
The Vector class represents a mathematical vector, which is useful in its own right, and also constitutes a row or column of a Matrix.
Method Catalogue
To create a Vector:
- Vector.[](*array)
- Vector.elements(array, copy = true)
To access elements:
- [](i)
To enumerate the elements:
- #each2(v)
- #collect2(v)
Vector arithmetic:
- *(x) "is matrix or number"
- +(v)
- -(v)
Vector functions:
- #inner_product(v)
- #collect
- #map
- #map2(v)
- #r
- #size
Conversion to other data types:
- #covector
- #to_a
- #coerce(other)
String representations:
- #to_s
- #inspect
Примеси
Методы класса
Методы объекта
[], *, +, -, ==, clone, coerce, collect2, collect, compare_by, covector, each2, eqn?, hash, init_elements, inner_product, inspect, map2, map, r, size, to_a, to_s
Vector::[]Править
Vector::[](*array)
Создает Vector из списка элементов.
Vector[7, 4, ...]
Vector::elementsПравить
Vector::elements(array, copy = true)
Creates a vector from an Array. The optional second argument specifies whether the array itself or a copy is used internally.
Vector::newПравить
Vector::new(method, array, copy)
For internal use.
Vector#*Править
*(x)
Multiplies the vector by x, where x is a number or another vector.
Vector#+Править
+(v)
Vector addition.
Vector#-Править
-(v)
Vector subtraction.
Vector#==Править
==(other)
Returns true iff the two vectors have the same elements in the same order.
(еще известен как eqn?)
Vector#[]Править
[](i)
Returns element number i (starting at zero) of the vector.
Vector#cloneПравить
clone()
Return a copy of the vector.
Vector#coerceПравить
coerce(other)
FIXME: describe Vector#coerce.
Vector#collectПравить
collect( {|e| ...}
Like Array#collect.
(еще известен как map)
Vector#collect2Править
collect2(v) {|e1, e2| ...}
Collects (as in Enumerable#collect) over the elements of this vector and v in conjunction.
Vector#compare_byПравить
compare_by(elements)
For internal use.
Vector#covectorПравить
covector()
Creates a single-row matrix from this vector.
Vector#each2Править
each2(v) {|e1, e2| ...}
Iterate over the elements of this vector and v in conjunction.
Vector#eqn?Править
eqn?(other)
Alias for #==
Vector#hashПравить
hash()
Return a hash-code for the vector.
Vector#init_elementsПравить
init_elements(array, copy)
For internal use.
Vector#inner_productПравить
inner_product(v)
Returns the inner product of this vector with the other.
Vector[4,7].inner_product Vector[10,1] => 47
Vector#inspectПравить
inspect()
Overrides Object#inspect
Vector#mapПравить
map(
Alias for #collect
Vector#map2Править
map2(v) {|e1, e2| ...}
Like Vector#collect2, but returns a Vector instead of an Array.
Vector#rПравить
r()
Returns the modulus (Pythagorean distance) of the vector.
Vector[5,8,2].r => 9.643650761
Vector#sizeПравить
size()
Returns the number of elements in the vector.
Vector#to_aПравить
to_a()
Returns the elements of the vector in an array.
Vector#to_sПравить
to_s()
Overrides Object#to_s