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