struct GSL::Vector
- GSL::Vector
- Struct
- Value
- Object
Included Modules
- Indexable::Mutable(Float64)
Defined in:
gsl/base/vector.crgsl/maths/basic/vector.cr
gsl/maths/statistics/vector.cr
Constructors
Instance Method Summary
- #*(n : Int32 | Float64)
- #*(n : GSL::Vector)
- #+(n : Int32 | Float64)
- #+(n : GSL::Vector)
- #-(n : Int32 | Float64)
- #-(n : GSL::Vector)
- #/(n : Int32 | Float64)
- #/(n : GSL::Vector)
-
#<<(n : Float64 | Int32) : Vector
alias of push methods
- #==(n : GSL::Vector) : Bool
- #clone
-
#concat(n : GSL::Vector) : Vector
concatinate two different vector and return a new vector
- #copy
- #dot(n : GSL::Vector)
-
#empty? : Bool
return true if current vector's elements are all 0
-
#freqs
alias for frequencies
- #frequencies
-
#has_neg? : Bool
return true if current vector has negtive element in it.
-
#head : Vector
return the first five elements in vector of current vector
-
#inner_product(n : GSL::Vector)
same as dot function
-
#inspect
Returns an unambiguous and information-rich string representation of this object, typically intended for developers.
-
#max_index : UInt64
return the index of maximum value of current vector note: if there are multiple same maximum value then only return the first one.
-
#mean : Float64
calculate the mean of the vector's elements
-
#min_index : UInt64
return the index of minimum value of current vector note: if there are multiple same minimum value then only return the first one.
-
#minmax_index : Array(UInt64)
return the index of minimum and maximum value of current vector
- #mode
-
#neg? : Bool
return true if current vector's elements are all negtive
- #pointer
-
#pos? : Bool
return true if current vector's elements are all positive
- #proportion(n : Float64 | Int32)
-
#push(n : Float64 | Int32) : Vector
Add element to the button of vector
- #ranked
- #raw : LibGSL::Gsl_vector
-
#replace(n : GSL::Vector) : Vector
replace current vector with input vector note that two vector should have the same length
-
#reverse
return a new vector with reversed elements of current vector
-
#reverse! : Vector
reverse elements of current vector
-
#set_all(n : Int32 | Float64) : Vector
return a new value with the same length as current vector's and all elements are set to input value
-
#set_all!(n : Int32 | Float64) : Vector
set current vector's elements to input value
-
#set_basis(n : Int32) : Vector
return a new vector with the same length of current vector but all values are zero except the input index
-
#set_basis!(n : Int32) : Vector
set current vector's elements to zero except the input index
-
#set_zero : Vector
return a new vector with a length same as current vector but elements are set to zero
-
#set_zero! : Vector
set current vector's elements to zero
-
#size : Int32
Returns the number of elements in this container.
-
#sort : Vector
return a new vector in ascending order
-
#sort! : Vector
change current vector in ascending order
-
#sum
Adds all the elements in the collection together.
-
#tail : Vector
return the last five elements in vector of current vector
-
#to_array : Array(Float64)
alias to to_a
-
#to_s : String
Returns a nicely readable and concise string representation of this object, typically intended for users.
- #to_slice
- #to_unsafe
-
#unsafe_fetch(index : Int)
Returns the element at the given index, without doing any bounds check.
-
#unsafe_put(index : Int, value : T)
Sets the element at the given index to value, without doing any bounds check.
Constructor Detail
Instance Method Detail
concatinate two different vector and return a new vector
a = [1,2,3].to_vector
b = [2,3,4].to_vector
a.concat b => GSL::Vector: [1.0,2.0,3.0,2.0,3.0,4.0]
return true if current vector's elements are all 0
a = [0,0,0].to_vector
b = [1,0,0].to_vector
a.empty? => true
b.empty? => false
return true if current vector has negtive element in it.
a = [-1,-1,1].to_vector
b = [1,0,0].to_vector
a.empty? => true
b.empty? => false
return the first five elements in vector of current vector
a = [1,2,3,4,5,6,7,8]to_vector
a.head => GSL::Vector: [1.0,2.0,3.0,4.0,5.0]
Returns an unambiguous and information-rich string representation of this object, typically intended for developers.
This method should usually not be overridden. It delegates to
#inspect(IO)
which can be overridden for custom implementations.
Also see #to_s
.
return the index of maximum value of current vector note: if there are multiple same maximum value then only return the first one.
a = [1,2,3].to_vector
a.max_index => 2
calculate the mean of the vector's elements
a = [0.0, -5.0, 7.3].to_vector.mean
a => 0.76666666666666661
return the index of minimum value of current vector note: if there are multiple same minimum value then only return the first one.
a = [1,2,3].to_vector
a.min_index => 0
return the index of minimum and maximum value of current vector
a = [1, 2, 3].to_vector
min, max = a.minmax_index
min = 0
max = 2
return true if current vector's elements are all negtive
a = [-1,-1,-1].to_vector
b = [-1,0,0].to_vector
a.empty? => true
b.empty? => false
return true if current vector's elements are all positive
a = [1,1,1].to_vector
b = [-1,0,0].to_vector
a.empty? => true
b.empty? => false
Add element to the button of vector
a = [1,2,3].to_vector
a.push 4 => GSL::Vector: [1.0,2.0,3.0,4.0]
replace current vector with input vector note that two vector should have the same length
a = [1,2,3].to_vector
b = [2,3,4].to_vector
c = [2,3,4,5].to_vector
a.replace b
a => GSL::Vector: [2.0,3.0,4.0]
a.replace c => length error
return a new vector with reversed elements of current vector
a = [1,2,3].to_vector
a.reverse => GSL::Vector: [3.0,2.0,1.0]
a => GSL::Vector [1.0,2.0,3.0]
reverse elements of current vector
a = [1,2,3].to_vector
a.reverse! => GSL::Vector: [3.0,2.0,1.0]
a => GSL::Vector: [3.0,2.0,1.0]
return a new value with the same length as current vector's and all elements are set to input value
a = [-1,-1,1].to_vector
a.set_all! 2 => GSL::Vector: [2.0,2.0,2.0]
a => GSL::Vector: [-1.0,-1.0,1.0]
set current vector's elements to input value
a = [-1,-1,1].to_vector
a.set_all! 2 => GSL::Vector: [2.0,2.0,2.0]
a => GSL::Vector: [2.0,2.0,2.0]
return a new vector with the same length of current vector but all values are zero except the input index
a = [-1,-1,1].to_vector
a.set_basis 2 => GSL::Vector: [0.0,0.0,1.0]
a => GSL::Vector: [-1.0,-1.0,1.0]
set current vector's elements to zero except the input index
a = [-1,-1,1].to_vector
a.set_basis! 2 => GSL::Vector: [0.0,0.0,1.0]
a => GSL::Vector: [0.0,0.0,1.0]
return a new vector with a length same as current vector but elements are set to zero
a = [-1,-1,1].to_vector
a.set_zero => GSL::Vector: [0.0,0.0,0.0]
a => GSL::Vector: [-1.0,-1.0,1.0]
set current vector's elements to zero
a = [-1,-1,1].to_vector
a.set_zero => GSL::Vector: [0.0,0.0,0.0]
a => GSL::Vector: [0.0,0.0,0.0]
Returns the number of elements in this container.
return a new vector in ascending order
a = [2,5,3,7,1].to_vector
a.sort => GSL::Vector: [1.0,2.0,3.0,5.0,7.0]
a => GSL::Vector: [2.0,5.0,3.0,7.0,1.0]
change current vector in ascending order
a = [2,5,3,7,1].to_vector
a.sort! => GSL::Vector: [1.0,2.0,3.0,5.0,7.0]
a => GSL::Vector: [1.0,2.0,3.0,5.0,7.0]
Adds all the elements in the collection together.
Expects all element types to respond to #+
method.
[1, 2, 3, 4, 5, 6].sum # => 21
This method calls .additive_identity
on the yielded type to determine the
type of the sum value.
If the collection is empty, returns additive_identity
.
([] of Int32).sum # => 0
return the last five elements in vector of current vector
a = [1,2,3,4,5,6,7,8]to_vector
a.tail => GSL::Vector: [2.0,3.0,4.0,5.0,6.0]
Returns a nicely readable and concise string representation of this object, typically intended for users.
This method should usually not be overridden. It delegates to
#to_s(IO)
which can be overridden for custom implementations.
Also see #inspect
.
Returns the element at the given index, without doing any bounds check.
Indexable
makes sure to invoke this method with index in 0...size
,
so converting negative indices to positive ones is not needed here.
Clients never invoke this method directly. Instead, they access
elements with #[](index)
and #[]?(index)
.
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.
Sets the element at the given index to value, without doing any bounds check.
Indexable::Mutable
makes sure to invoke this method with index in
0...size
, so converting negative indices to positive ones is not needed
here.
Clients never invoke this method directly. Instead, they modify elements
with #[]=(index, value)
.
This method should only be directly invoked if you are absolutely sure the index is in bounds, to avoid a bounds check for a small boost of performance.