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