ColVector¶
- class ColVector(*args, **kwargs)¶
Bases:
ArrayDouble2D
Implementation of column vector and the associated operations.
This class provides a data structure for a column vector that contains values of double. It contains also some functions to achieve a set of operations on these vectors.
The vpColVector class is derived from vpArray2D<double> .
The code below shows how to create a 3-element column vector of doubles, set the element values and access them:
#include <visp3/code/vpColVector.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v(3); v[0] = -1; v[1] = -2.1; v[2] = -3; std::cout << "v:" << std::endl; for (unsigned int i = 0; i < v.size(); ++i) { std::cout << v[i] << std::endl; } }
Once build, this previous code produces the following output:
v: -1 -2.1 -3
You can also use operator<< to initialize a column vector as previously:
#include <visp3/code/vpColVector.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v; v << -1, -2.1, -3; std::cout << "v:" << v << std::endl; }
If ViSP is build with c++11 enabled, you can do the same using:
#include <visp3/code/vpColVector.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v({-1, -2.1, -3}); std::cout << "v:\n" << v << std::endl; }
The vector could also be initialized using operator=(const std::initializer_list< double > &)
#ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v; v = {-1, -2.1, -3}; }
JSON serialization
Since ViSP 3.6.0, if ViSP is build with soft_tool_json 3rd-party we introduce JSON serialization capabilities for vpColVector . The following sample code shows how to save a pose vector in a file named col-vector.json and reload the values from this JSON file.
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { #if defined(VISP_HAVE_NLOHMANN_JSON) std::string filename = "col-vector.json"; { vpColVector v({ 1, 2, 3, 4 }); std::ofstream file(filename); const nlohmann::json j = v; file << j; file.close(); } { std::ifstream file(filename); const nlohmann::json j = nlohmann::json::parse(file); vpColVector v; v = j.get<vpColVector>(); file.close(); std::cout << "Read homogeneous matrix from " << filename << ":\n" << v.t() << std::endl; } #endif }
If you build and execute the sample code, it will produce the following output:
Read homogeneous matrix from col-vector.json: 1 2 3 4
The content of the pose-vector.json file is the following:
$ cat col-vector.json {"cols":1,"data":[1.0,2.0,3.0,4.0],"rows":4,"type":"vpColVector"}
Overloaded function.
__init__(self: visp._visp.core.ColVector) -> None
Basic constructor that creates an empty 0-size column vector.
__init__(self: visp._visp.core.ColVector, n: int) -> None
__init__(self: visp._visp.core.ColVector, n: int, val: float) -> None
Construct a column vector of size n. Each element is set to val .
__init__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> None
Copy constructor that allows to construct a column vector from an other one.
__init__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector, r: int, nrows: int) -> None
Construct a column vector from a part of an input column vector v .
The sub-vector starting from v[r] element and ending on v[r+nrows-1] element is used to initialize the constructed column vector.
Note
See init()
- Parameters:
- v
Input column vector used for initialization.
- r
row index in v that corresponds to the first element of the column vector to construct.
- nrows
Number of rows of the constructed column vector.
__init__(self: visp._visp.core.ColVector, v: visp._visp.core.RotationVector) -> None
__init__(self: visp._visp.core.ColVector, p: visp._visp.core.PoseVector) -> None
__init__(self: visp._visp.core.ColVector, t: visp._visp.core.TranslationVector) -> None
__init__(self: visp._visp.core.ColVector, M: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.ColVector, M: visp._visp.core.Matrix, j: int) -> None
Constructor that takes column j of matrix M .
__init__(self: visp._visp.core.ColVector, v: list[float]) -> None
__init__(self: visp._visp.core.ColVector, v: list[float]) -> None
__init__(self: visp._visp.core.ColVector, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.ColVector, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a column vector by copying a 1D numpy array.
- Parameters:
- np_array
The numpy 1D array to copy.
Methods
Overloaded function.
Removes all elements from the vector (which are destroyed), leaving the container with a size of 0.
Print to be used as part of a C++ code later.
Compute and return the cross product of two 3-dimension vectors: \(a \times b\) .
Compute and return the cross product of two vectors \(a \times b\) .
Print/save a column vector in csv format.
Converts a column vector containing angles in degrees into radians and returns a reference to the vector.
Compute end return the dot product of two column vectors:
Extract a sub-column vector from a column vector.
Compute and return the Frobenius norm \(||v|| = \sqrt{ \sum_{v_{i}^2}}\) of all the elements \(v_{i}\) of the column vector \(\bf v\) that is of dimension \(m\) .
Overloaded function.
Compute and return the infinity norm \({||v||}_{\infty} = max\left({\mid v_{i} \mid}\right)\) with \(i \in \{0, ..., m-1\}\) where m is the vector size and \(v_i\) an element of the vector.
Initialize the column vector from a part of an input column vector v .
Overloaded function.
Return a column vector with elements of v that are reverse sorted with values going from greatest to lowest.
Compute the mean value of all the elements of the vector.
Compute the median value of all the elements of the vector.
Overloaded function.
Numpy view of the underlying array data.
Pretty print a column vector.
Note
See deg2rad()
Overloaded function.
Overloaded function.
Compute the skew symmetric matrix \([{\bf v}]_\times\) of vector v.
Return a column vector with elements of v that are sorted with values going from lowest to greatest.
Overloaded function.
Overloaded function.
Compute the standard deviation value of all the elements of the vector.
Returns a C++ code representation of this data array (see cppPrint in the C++ documentation)
Returns the CSV representation of this data array (see csvPrint in the C++ documentation)
Returns the CSV representation of this data array (see maplePrint in the C++ documentation)
Returns the Matlab representation of this data array (see matlabPrint in the C++ documentation)
Return the sum of all the elements \(v_{i}\) of the column vector \(\bf v\) that is of dimension \(m\) .
Return the sum of squares of all the elements \(v_{i}\) of the column vector \(\bf v\) that is of dimension \(m\) .
Overloaded function.
- return:
The corresponding std::vector<double>.
Overloaded function.
Inherited Methods
Return the array max value.
Return the number of rows of the 2D array.
Overloaded function.
Return the array min value.
Insert array B in array A at the given position.
Overloaded function.
Return the number of elements of the 2D array.
Save an array in a YAML-formatted file.
Return the number of columns of the 2D array.
Operators
Overloaded function.
__doc__
Overloaded function.
Overloaded function.
Operator that allows to add two column vectors.
Operator that allows to multiply each element of a column vector by a scalar.
Overloaded function.
Operator that allows to subtract two column vectors.
Operator that allows to divide each element of a column vector by a scalar.
__module__
Overloaded function.
Overloaded function.
Operator that allows to negate all the column vector elements.
Operator subtraction of two vectors this = this - v
Operator that allows to divide each element of a column vector by a scalar.
Attributes
__annotations__
- __add__(*args, **kwargs)¶
Overloaded function.
__add__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Operator that allows to add two column vectors.
__add__(self: visp._visp.core.ColVector, t: visp._visp.core.TranslationVector) -> visp._visp.core.TranslationVector
Operator that allows to add a column vector to a translation vector.
- Parameters:
- t
3-dimension translation vector to add.
- Returns:
The sum of the current column vector (*this) and the translation vector to add.
vpTranslationVector t1(1,2,3); vpColVector v(3); v[0] = 4; v[1] = 5; v[2] = 6; vpTranslationVector t2; t2 = v + t1; // t1 and v leave unchanged // t2 is now equal to : 5, 7, 9
- __eq__(*args, **kwargs)¶
Overloaded function.
__eq__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> bool
Compare two column vectors.
- Parameters:
- v
Vector to compare with.
- Returns:
true when their respective size and their respective values are the same, false when their size or values differ.
__eq__(self: visp._visp.core.ColVector, v: float) -> bool
Compare a column vector to a floating point value.
- Parameters:
- v
Floating point value to compare with.
- Returns:
true when all the values of the vector are equal to the floating point value v , false otherwise.
- __getitem__(*args, **kwargs)¶
Overloaded function.
__getitem__(self: visp._visp.core.ColVector, arg0: int) -> float
__getitem__(self: visp._visp.core.ColVector, arg0: slice) -> numpy.ndarray[numpy.float64]
- __iadd__(self, v: visp._visp.core.ColVector) visp._visp.core.ColVector ¶
Operator that allows to add two column vectors.
- __imul__(self, x: float) visp._visp.core.ColVector ¶
Operator that allows to multiply each element of a column vector by a scalar.
vpColVector v(3); v[0] = 1; v[1] = 2; v[2] = 3; v *= 3; // v is now equal to : [3, 6, 9]
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.ColVector) -> None
Basic constructor that creates an empty 0-size column vector.
__init__(self: visp._visp.core.ColVector, n: int) -> None
__init__(self: visp._visp.core.ColVector, n: int, val: float) -> None
Construct a column vector of size n. Each element is set to val .
__init__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> None
Copy constructor that allows to construct a column vector from an other one.
__init__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector, r: int, nrows: int) -> None
Construct a column vector from a part of an input column vector v .
The sub-vector starting from v[r] element and ending on v[r+nrows-1] element is used to initialize the constructed column vector.
Note
See init()
- Parameters:
- v
Input column vector used for initialization.
- r
row index in v that corresponds to the first element of the column vector to construct.
- nrows
Number of rows of the constructed column vector.
__init__(self: visp._visp.core.ColVector, v: visp._visp.core.RotationVector) -> None
__init__(self: visp._visp.core.ColVector, p: visp._visp.core.PoseVector) -> None
__init__(self: visp._visp.core.ColVector, t: visp._visp.core.TranslationVector) -> None
__init__(self: visp._visp.core.ColVector, M: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.ColVector, M: visp._visp.core.Matrix, j: int) -> None
Constructor that takes column j of matrix M .
__init__(self: visp._visp.core.ColVector, v: list[float]) -> None
__init__(self: visp._visp.core.ColVector, v: list[float]) -> None
__init__(self: visp._visp.core.ColVector, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.ColVector, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a column vector by copying a 1D numpy array.
- Parameters:
- np_array
The numpy 1D array to copy.
- __isub__(self, v: visp._visp.core.ColVector) visp._visp.core.ColVector ¶
Operator that allows to subtract two column vectors.
- __itruediv__(self, x: float) visp._visp.core.ColVector ¶
Operator that allows to divide each element of a column vector by a scalar.
vpColVector v(3); v[0] = 8; v[1] = 4; v[2] = 2; v /= 2; // v is now equal to : [4, 2, 1]
- __mul__(*args, **kwargs)¶
Overloaded function.
__mul__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> float
Operator that performs the dot product between two column vectors.
Note
See dotProd()
__mul__(self: visp._visp.core.ColVector, v: visp._visp.core.RowVector) -> visp._visp.core.Matrix
Multiply a column vector by a row vector.
- Parameters:
- v
Row vector.
- Returns:
The resulting matrix.
__mul__(self: visp._visp.core.ColVector, M: visp._visp.core.Matrix) -> visp._visp.core.Matrix
Multiply a column vector by a matrix.
- Parameters:
- M
Matrix.
- Returns:
The resulting matrix.
__mul__(self: visp._visp.core.ColVector, x: float) -> visp._visp.core.ColVector
Operator that allows to multiply each element of a column vector by a scalar.
vpColVector v(3); v[0] = 1; v[1] = 2; v[2] = 3; vpColVector w = v * 3; // v is unchanged // w is now equal to : [3, 6, 9]
- Parameters:
- x
The scalar.
- Returns:
The column vector multiplied by the scalar. The current column vector (*this) is unchanged.
- __ne__(*args, **kwargs)¶
Overloaded function.
__ne__(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> bool
Compare two column vectors.
- Parameters:
- v
Vector to compare with.
- Returns:
true when their respective size or their values differ, false when their size and values are the same.
__ne__(self: visp._visp.core.ColVector, v: float) -> bool
Compare a column vector to a floating point value.
- Parameters:
- v
Floating point value to compare with.
- Returns:
true when at least one value of the vector differ from the floating point value v . false when all the vector values are equal to v .
- __neg__(self) visp._visp.core.ColVector ¶
Operator that allows to negate all the column vector elements.
vpColVector r(3, 1); // r contains [1 1 1]^T vpColVector v = -r; // v contains [-1 -1 -1]^T
- __sub__(self, v: visp._visp.core.ColVector) visp._visp.core.ColVector ¶
Operator subtraction of two vectors this = this - v
- __truediv__(self, x: float) visp._visp.core.ColVector ¶
Operator that allows to divide each element of a column vector by a scalar.
vpColVector v(3); v[0] = 8; v[1] = 4; v[2] = 2; vpColVector w = v / 2; // v is unchanged // w is now equal to : [4, 2, 1]
- clear(self) None ¶
Removes all elements from the vector (which are destroyed), leaving the container with a size of 0.
- static conv2(*args, **kwargs)¶
Overloaded function.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, mode: str) -> visp._visp.core.ArrayDouble2D
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7f422775e920>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First matrix.
- kernel
Second matrix.
- mode
Convolution mode: “full” (default), “same”, “valid”.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7f4227778580>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First array.
- kernel
Second array.
- res
Result.
- mode
Convolution mode: “full” (default), “same”, “valid”.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, mode: str) -> visp._visp.core.ArrayDouble2D
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7f422775e920>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First matrix.
- kernel
Second matrix.
- mode
Convolution mode: “full” (default), “same”, “valid”.
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None
Perform a 2D convolution similar to Matlab conv2 function: \(M \star kernel\) .
<unparsed image <doxmlparser.compound.docImageType object at 0x7f4227778580>>
Note
This is a very basic implementation that does not use FFT.
- Parameters:
- M
First array.
- kernel
Second array.
- res
Result.
- mode
Convolution mode: “full” (default), “same”, “valid”.
- cppPrint(self: visp._visp.core.ColVector, os: std::ostream, matrixName: str = A, octet: bool = false) std::ostream ¶
Print to be used as part of a C++ code later.
The following code shows how to use this function:
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v(3); for (unsigned int i=0; i<v.size(); ++i) v[i] = i; v.cppPrint(std::cout, "v"); }
It produces the following output that could be copy/paste in a C++ code:
vpColVector v (3); v[0] = 0; v[1] = 1; v[2] = 2;
Note
See print() , matlabPrint() , maplePrint()
- Parameters:
- os
the stream to be printed in.
- matrixName
name of the column vector, “A” by default.
- octet
if false, print using double, if true, print byte per byte each bytes of the double array.
- static cross(a: visp._visp.core.ColVector, b: visp._visp.core.ColVector) visp._visp.core.ColVector ¶
Compute and return the cross product of two 3-dimension vectors: \(a \times b\) .
Note
See crossProd() , dotProd() , operator*(const vpColVector &)
- Parameters:
- a: visp._visp.core.ColVector¶
3-dimension column vector.
- b: visp._visp.core.ColVector¶
3-dimension column vector.
- Returns:
The cross product \(a \times b\) .
- static crossProd(a: visp._visp.core.ColVector, b: visp._visp.core.ColVector) visp._visp.core.ColVector ¶
Compute and return the cross product of two vectors \(a \times b\) .
Note
See dotProd()
- Parameters:
- a: visp._visp.core.ColVector¶
3-dimension column vector.
- b: visp._visp.core.ColVector¶
3-dimension column vector.
- Returns:
The cross product \(a \times b\) .
- csvPrint(self: visp._visp.core.ColVector, os: std::ostream) std::ostream ¶
Print/save a column vector in csv format.
The following code
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { std::ofstream ofs("log.csv", std::ofstream::out); vpColVector v(3); for (unsigned int i=0; i<v.size(); ++i) v[i] = i; v.csvPrint(ofs); ofs.close(); }
produces log.csv file that contains:
0 1 2
- deg2rad(self) visp._visp.core.ColVector ¶
Converts a column vector containing angles in degrees into radians and returns a reference to the vector.
Note
See rad2deg()
- Returns:
A reference to the vector with values expressed in [rad].
- static dotProd(a: visp._visp.core.ColVector, b: visp._visp.core.ColVector) float ¶
Compute end return the dot product of two column vectors:
\[a \cdot b = \sum_{i=0}^n a_i * b_i\]where n is the dimension of both vectors.
Note
See cross() , crossProd()
- extract(self, r: int, colsize: int) visp._visp.core.ColVector ¶
Extract a sub-column vector from a column vector.
vpColVector v1; for (unsigned int i=0; i<4; ++i) v1.stack(i); // v1 is equal to [0 1 2 3]^T vpColVector v2 = v1.extract(1, 3); // v2 is equal to [1 2 3]^T
- frobeniusNorm(self) float ¶
Compute and return the Frobenius norm \(||v|| = \sqrt{ \sum_{v_{i}^2}}\) of all the elements \(v_{i}\) of the column vector \(\bf v\) that is of dimension \(m\) .
Note
See infinityNorm()
- Returns:
The Frobenius norm if the vector is initialized, 0 otherwise.
- hadamard(*args, **kwargs)¶
Overloaded function.
hadamard(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Compute the Hadamard product (element wise vector multiplication).
- Parameters:
- v
Second vector;
- Returns:
v1.hadamard(v2) The kronecker product : \(v1 \circ v2 = (v1 \circ v2)_{i} = (v1)_{i} (v2)_{i}\)
hadamard(self: visp._visp.core.ArrayDouble2D, m: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
- Parameters:
- m
Second matrix;
- Returns:
m1.hadamard(m2) The Hadamard product : \(m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j}\)
- infinityNorm(self) float ¶
Compute and return the infinity norm \({||v||}_{\infty} = max\left({\mid v_{i} \mid}\right)\) with \(i \in \{0, ..., m-1\}\) where m is the vector size and \(v_i\) an element of the vector.
Note
See frobeniusNorm()
- Returns:
The infinity norm if the matrix is initialized, 0 otherwise.
- init(self, v: visp._visp.core.ColVector, r: int, nrows: int) None ¶
Initialize the column vector from a part of an input column vector v .
The sub-vector starting from v[r] element and ending on v[r+nrows-1] element is used to initialize the constructed column vector.
The following code shows how to use this function:
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v(4); int val = 0; for(size_t i=0; i<v.getRows(); ++i) { v[i] = val++; } std::cout << "v: " << v.t() << std::endl; vpColVector w; w.init(v, 0, 2); std::cout << "w: " << w.t() << std::endl; }
It produces the following output:
v: 0 1 2 3 w: 1 2
- insert(*args, **kwargs)¶
Overloaded function.
insert(self: visp._visp.core.ColVector, i: int, v: visp._visp.core.ColVector) -> None
Insert a column vector.The following example shows how to use this function:
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v(4); for (unsigned int i=0; i < v.size(); ++i) v[i] = i; std::cout << "v: " << v.t() << std::endl; vpColVector w(2); for (unsigned int i=0; i < w.size(); ++i) w[i] = i+10; std::cout << "w: " << w.t() << std::endl; v.insert(1, w); std::cout << "v: " << v.t() << std::endl; }
It produces the following output:
v: 0 1 2 3 w: 10 11 v: 0 10 11 3
- Parameters:
- i
Index of the first element to introduce. This index starts from 0.
- v
Column vector to insert.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None
Insert array A at the given position in the current array.
Warning
Throw vpException::dimensionError if the dimensions of the matrices do not allow the operation.
- Parameters:
- A
The array to insert.
- r
The index of the row to begin to insert data.
- c
The index of the column to begin to insert data.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, r: int, c: int) -> visp._visp.core.ArrayDouble2D
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- Parameters:
- A
Main array.
- B
Array to insert.
- r
Index of the row where to add the array.
- c
Index of the column where to add the array.
- Returns:
Array with B insert in A.
- static insertStatic(A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, C: visp._visp.core.ArrayDouble2D, r: int, c: int) None ¶
Insert array B in array A at the given position.
Warning
Throw exception if the sizes of the arrays do not allow the insertion.
- Parameters:
- A: visp._visp.core.ArrayDouble2D¶
Main array.
- B: visp._visp.core.ArrayDouble2D¶
Array to insert.
- C: visp._visp.core.ArrayDouble2D¶
Result array.
- r: int¶
Index of the row where to insert array B.
- c: int¶
Index of the column where to insert array B.
- static invSort(v: visp._visp.core.ColVector) visp._visp.core.ColVector ¶
Return a column vector with elements of v that are reverse sorted with values going from greatest to lowest.
Example:
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v(10); v[0] = 5; v[1] = 7; v[2] = 4; v[3] = 2; v[4] = 8; v[5] = 6; v[6] = 1; v[7] = 9; v[8] = 0; v[9] = 3; std::cout << "v: " << v.t() << std::endl; vpColVector s = vpColVector::invSort(v); std::cout << "s: " << s.t() << std::endl; }
Output:
v: 5 7 4 2 8 6 1 9 0 3 s: 9 8 7 6 5 4 3 2 1 0
Note
See sort()
- static mean(v: visp._visp.core.ColVector) float ¶
Compute the mean value of all the elements of the vector.
- static median(v: visp._visp.core.ColVector) float ¶
Compute the median value of all the elements of the vector.
- normalize(*args, **kwargs)¶
Overloaded function.
normalize(self: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Normalize the column vector.
Considering the n-dim column vector \({\bf x} = (x_0, x_1, \ldots, n_{n-1})\) normalize each vector element \(i\) :
\[x_i = \frac{x_i}{\sqrt{\sum_{i=0}^{n-1}x^2_i}} \]- Returns:
A reference to the normalized vector.
normalize(self: visp._visp.core.ColVector, x: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Normalize a column vector.
Considering the n-dim column vector \({\bf x} = (x_0, x_1, \ldots, n_{n-1})\) normalize each vector element \(i\) :
\[x_i = \frac{x_i}{\sqrt{\sum_{i=0}^{n-1} x^2_i}} \]- Parameters:
- x
As input, the vector to normalize, as output the normalized vector.
- Returns:
A reference to the normalized vector.
- numpy(self) numpy.ndarray[numpy.float64] ¶
Numpy view of the underlying array data. This numpy view can be used to directly modify the array.
- print(self: visp._visp.core.ColVector, s: std::ostream, length: int, intro: str = 0) int ¶
Pretty print a column vector. The data are tabulated. The common widths before and after the decimal point are set with respect to the parameter maxlen.
Note
See std::ostream & operator<<(std::ostream &s, const vpArray2D<Type> &A)
- Parameters:
- s
Stream used for the printing.
- length
The suggested width of each vector element. The actual width grows in order to accommodate the whole integral part, and shrinks if the whole extent is not needed for all the numbers.
- intro
The introduction which is printed before the vector. Can be set to zero (or omitted), in which case the introduction is not printed.
- Returns:
Returns the common total width for all vector elements.
- rad2deg(self) visp._visp.core.ColVector ¶
Note
See deg2rad()
- Returns:
A reference to the vector with values expressed in [deg].
- reshape(*args, **kwargs)¶
Overloaded function.
reshape(self: visp._visp.core.ColVector, M: visp._visp.core.Matrix, nrows: int, ncols: int) -> None
Reshape the column vector in a matrix.
The following example shows how to use this method.
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { int var=0; vpMatrix mat(3, 4); for (int i = 0; i < 3; ++i) for (int j = 0; j < 4; ++j) mat[i][j] = ++var; std::cout << "mat: \n" << mat << std::endl; vpColVector col = mat.stackColumns(); std::cout << "column vector: \n" << col << std::endl; vpMatrix remat = col.reshape(3, 4); std::cout << "remat: \n" << remat << std::endl; }
If you run the previous example, you get:
mat: 1 2 3 4 5 6 7 8 9 10 11 12 column vector: 1 5 9 2 6 10 3 7 11 4 8 12 remat: 1 2 3 4 5 6 7 8 9 10 11 12
- Parameters:
- M
the reshaped matrix.
- nrows
number of rows of the matrix.
- ncols
number of columns of the matrix.
reshape(self: visp._visp.core.ColVector, nrows: int, ncols: int) -> visp._visp.core.Matrix
Reshape the column vector in a matrix.
Note
See reshape(vpMatrix &, const unsigned int &, const unsigned int &)
- Parameters:
- nrows
number of rows of the matrix
- ncols
number of columns of the matrix
- Returns:
The reshaped matrix.
reshape(self: visp._visp.core.ArrayDouble2D, nrows: int, ncols: int) -> None
- resize(*args, **kwargs)¶
Overloaded function.
resize(self: visp._visp.core.ColVector, i: int, flagNullify: bool = true) -> None
Modify the size of the column vector.
- Parameters:
- i
Size of the vector. This value corresponds to the vector number of rows.
- flagNullify
If true, set the data to zero.
resize(self: visp._visp.core.ColVector, nrows: int, ncols: int, flagNullify: bool) -> None
Resize the column vector to a nrows-dimension vector. This function can only be used with ncols = 1.
- Parameters:
- nrows
Vector number of rows. This value corresponds to the size of the vector.
- ncols
Vector number of columns. This value should be set to 1.
- flagNullify
If true, set the data to zero.
resize(self: visp._visp.core.ArrayDouble2D, nrows: int, ncols: int, flagNullify: bool = true, recopy_: bool = true) -> None
Set the size of the array and initialize all the values to zero.
- Parameters:
- nrows
number of rows.
- ncols
number of column.
- flagNullify
if true, then the array is re-initialized to 0 after resize. If false, the initial values from the common part of the array (common part between old and new version of the array) are kept. Default value is true.
- recopy_
if true, will perform an explicit recopy of the old data.
- static save(*args, **kwargs)¶
Overloaded function.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
Save a matrix to a file.
Warning : If you save the matrix as in a text file the precision is less than if you save it in a binary file.
Note
See load()
- Parameters:
- filename
Absolute file name.
- A
Array to be saved.
- binary
If true the matrix is saved in a binary file, else a text file.
- header
Optional line that will be saved at the beginning of the file.
- Returns:
Returns true if success.
- static saveYAML(filename: str, A: visp._visp.core.ArrayDouble2D, header: str =) bool ¶
Save an array in a YAML-formatted file.
Here is an example of outputs.
vpArray2D<double> M(3,4); vpArray2D::saveYAML("matrix.yml", M, "example: a YAML-formatted header"); vpArray2D::saveYAML("matrixIndent.yml", M, "example:\n - a YAML-formatted \ header\n - with inner indentation");
Content of matrix.yml:
example: a YAML-formatted header rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Content of matrixIndent.yml:
example: - a YAML-formatted header - with inner indentation rows: 3 cols: 4 data: - [0, 0, 0, 0] - [0, 0, 0, 0] - [0, 0, 0, 0]
Note
See loadYAML()
- Parameters:
- filename
absolute file name.
- A
array to be saved in the file.
- header
optional lines that will be saved at the beginning of the file. Should be YAML-formatted and will adapt to the indentation if any.
- Returns:
Returns true if success.
- static skew(v: visp._visp.core.ColVector) visp._visp.core.Matrix ¶
Compute the skew symmetric matrix \([{\bf v}]_\times\) of vector v.
\[\begin{split}\mbox{if} \quad {\bf v} = \left( \begin{array}{c} x \\y \\z \end{array}\right), \quad \mbox{then} \qquad [{\bf v}]_\times = \left( \begin{array}{ccc} 0 & -z & y \\z & 0 & -x \\-y & x & 0 \end{array}\right) \end{split}\]- Parameters:
- v: visp._visp.core.ColVector¶
Input vector used to compute the skew symmetric matrix.
- static sort(v: visp._visp.core.ColVector) visp._visp.core.ColVector ¶
Return a column vector with elements of v that are sorted with values going from lowest to greatest.
Example:
#include <visp3/core/vpColVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpColVector v(10); v[0] = 5; v[1] = 7; v[2] = 4; v[3] = 2; v[4] = 8; v[5] = 6; v[6] = 1; v[7] = 9; v[8] = 0; v[9] = 3; std::cout << "v: " << v.t() << std::endl; vpColVector s = vpColVector::sort(v); std::cout << "s: " << s.t() << std::endl; }
Output:
v: 5 7 4 2 8 6 1 9 0 3 s: 0 1 2 3 4 5 6 7 8 9
Note
See invSort()
- stack(*args, **kwargs)¶
Overloaded function.
stack(self: visp._visp.core.ColVector, d: float) -> None
Stack column vector with a new element at the end of the vector.
vpColVector v(3, 1); // v is equal to [1 1 1]^T v.stack(-2); // v is equal to [1 1 1 -2]^T
Note
See stack(const vpColVector &, const vpColVector &)
Note
See stack(const vpColVector &, const vpColVector &, vpColVector &)
- Parameters:
- d
Element to stack to the existing vector.
stack(self: visp._visp.core.ColVector, v: visp._visp.core.ColVector) -> None
Stack column vectors.
vpColVector v1(3, 1); // v1 is equal to [1 1 1]^T vpColVector v2(2, 3); // v2 is equal to [3 3]^T v1.stack(v2); // v1 is equal to [1 1 1 3 3]^T
Note
See stack(const vpColVector &, const double &)
Note
See stack(const vpColVector &, const vpColVector &)
Note
See stack(const vpColVector &, const vpColVector &, vpColVector &)
- Parameters:
- v
Vector to stack to the existing one.
- static stackVectors(*args, **kwargs)¶
Overloaded function.
stackVectors(A: visp._visp.core.ColVector, B: visp._visp.core.ColVector) -> visp._visp.core.ColVector
Stack column vectors.
vpColVector A(3); vpColVector B(5); vpColVector C; C = vpColVector::stack(A, B); // C = [A B]T // C is now an 8 dimension column vector
Note
See stack(const vpColVector &)
Note
See stack(const vpColVector &, const vpColVector &, vpColVector &)
- Parameters:
- A
Initial vector.
- B
Vector to stack at the end of A.
- Returns:
Stacked vector \([A B]^T\) .
stackVectors(A: visp._visp.core.ColVector, B: visp._visp.core.ColVector, C: visp._visp.core.ColVector) -> None
Stack column vectors.
vpColVector A(3); vpColVector B(5); vpColVector C; vpColVector::stack (A, B, C); // C = [A B]T // C is now an 8 dimension column vector
Note
See stack(const vpColVector &)
Note
See stack(const vpColVector &, const vpColVector &)
- Parameters:
- A
Initial vector.
- B
Vector to stack at the end of A.
- C
Resulting stacked vector \(C = [A B]^T\) .
- static stdev(v: visp._visp.core.ColVector, useBesselCorrection: bool = false) float ¶
Compute the standard deviation value of all the elements of the vector.
- strCppCode(self, name: str, byte_per_byte: bool = False) str ¶
Returns a C++ code representation of this data array (see cppPrint in the C++ documentation)
- strCsv(self) str ¶
Returns the CSV representation of this data array (see csvPrint in the C++ documentation)
- strMaple(self) str ¶
Returns the CSV representation of this data array (see maplePrint in the C++ documentation)
- strMatlab(self) str ¶
Returns the Matlab representation of this data array (see matlabPrint in the C++ documentation)
- sum(self) float ¶
Return the sum of all the elements \(v_{i}\) of the column vector \(\bf v\) that is of dimension \(m\) .
- Returns:
The value
\[\sum_{i=0}^{m-1} v_i \].
- sumSquare(self) float ¶
Return the sum of squares of all the elements \(v_{i}\) of the column vector \(\bf v\) that is of dimension \(m\) .
- Returns:
The value
\[\sum_{i=0}^{m-1} v_i^{2}\].
- t(*args, **kwargs)¶
Overloaded function.
t(self: visp._visp.core.ColVector) -> visp._visp.core.RowVector
Transpose the column vector. The resulting vector becomes a row vector.
t(self: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
Compute the transpose of the array.
- Returns:
vpArray2D<Type> C = A^T
- transpose(*args, **kwargs)¶
Overloaded function.
transpose(self: visp._visp.core.ColVector) -> visp._visp.core.RowVector
Transpose the column vector. The resulting vector becomes a row vector.
Note
See t()
transpose(self: visp._visp.core.ColVector, v: visp._visp.core.RowVector) -> None
Transpose the column vector. The resulting vector v becomes a row vector.
Note
See t()
-
__hash__ =
None
¶