RowVector¶
- class RowVector(*args, **kwargs)¶
Bases:
ArrayDouble2D
Implementation of row vector and the associated operations.
This class provides a data structure for a row vector that contains values of double. It contains also some functions to achieve a set of operations on these vectors.
The vpRowVector class is derived from vpArray2D<double> .
The code below shows how to create a 3-element row vector of doubles, set the element values and access them:
#include <visp3/code/vpRowVector.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRowVector 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::cout << std::endl; }
Once build, this previous code produces the following output:
v: -1 -2.1 -3
If ViSP is build with c++11 enabled, you can do the same using:
#include <visp3/code/vpRowVector.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRowVector 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 > &)
#include <visp3/code/vpRowVector.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRowVector v; v = {-1, -2.1, -3}; }
Overloaded function.
__init__(self: visp._visp.core.RowVector) -> None
Basic constructor that creates an empty 0-size row vector.
__init__(self: visp._visp.core.RowVector, n: int) -> None
__init__(self: visp._visp.core.RowVector, n: int, val: float) -> None
Construct a row vector of size n. Each element is set to val .
__init__(self: visp._visp.core.RowVector, v: visp._visp.core.RowVector) -> None
Copy constructor that allows to construct a row vector from an other one.
__init__(self: visp._visp.core.RowVector, v: visp._visp.core.RowVector, c: int, ncols: int) -> None
Construct a row vector from a part of an input row vector v .
The sub-vector starting from v[c] element and ending on v[c+ncols-1] element is used to initialize the constructed row vector.
Note
See init()
- Parameters:
- v
Input row vector used for initialization.
- c
column index in v that corresponds to the first element of the row vector to construct.
- ncols
Number of columns of the constructed row vector.
__init__(self: visp._visp.core.RowVector, M: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.RowVector, M: visp._visp.core.Matrix, i: int) -> None
Constructor that creates a row vector corresponding to row i of matrix M .
__init__(self: visp._visp.core.RowVector, v: list[float]) -> None
__init__(self: visp._visp.core.RowVector, v: list[float]) -> None
__init__(self: visp._visp.core.RowVector, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.RowVector, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a row 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.
Convert a column vector containing angles in degrees into radians.
Extract a sub-row vector from a row vector.
Compute and return the Frobenius norm \(||v|| = \sqrt{ \sum{v_{i}^2}}\) .
Overloaded function.
Initialize the row vector from a part of an input row vector v .
Overloaded function.
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 row vector.
Convert a column vector containing angles in radians into degrees.
Overloaded function.
Overloaded function.
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 row vector v(n).
Return the sum square of all the elements \(v_{i}\) of the row vector v(n).
Overloaded function.
- return:
The corresponding std::vector<double>.
Overloaded function.
Construct a row vector that is a view of a numpy array.
Inherited Methods
Return the number of columns of the 2D array.
Overloaded function.
Return the number of elements of the 2D array.
Overloaded function.
Return the number of rows of the 2D array.
Operators
Operator that allows to add to row vectors that have the same size.
__doc__
Comparison operator.
Overloaded function.
Operator that allows to add two row vectors that have the same size.
Operator that allows to multiply each element of a row vector by a scalar.
Overloaded function.
Operator that allows to subtract two row vectors that have the same size.
Operator that allows to divide each element of a row vector by a scalar.
__module__
Overloaded function.
Operator that allows to negate all the row vector elements.
Overloaded function.
Operator that allows to subtract to row vectors that have the same size.
Operator that allows to divide each element of a row vector by a scalar.
Attributes
__annotations__
- __add__(self, v: visp._visp.core.RowVector) visp._visp.core.RowVector ¶
Operator that allows to add to row vectors that have the same size.
- __eq__(self, v: visp._visp.core.RowVector) bool ¶
Comparison operator.
- __getitem__(*args, **kwargs)¶
Overloaded function.
__getitem__(self: visp._visp.core.RowVector, arg0: int) -> float
__getitem__(self: visp._visp.core.RowVector, arg0: slice) -> numpy.ndarray[numpy.float64]
- __iadd__(self, v: visp._visp.core.RowVector) visp._visp.core.RowVector ¶
Operator that allows to add two row vectors that have the same size.
- __imul__(self, x: float) visp._visp.core.RowVector ¶
Operator that allows to multiply each element of a row vector by a scalar.
vpRowVector 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.RowVector) -> None
Basic constructor that creates an empty 0-size row vector.
__init__(self: visp._visp.core.RowVector, n: int) -> None
__init__(self: visp._visp.core.RowVector, n: int, val: float) -> None
Construct a row vector of size n. Each element is set to val .
__init__(self: visp._visp.core.RowVector, v: visp._visp.core.RowVector) -> None
Copy constructor that allows to construct a row vector from an other one.
__init__(self: visp._visp.core.RowVector, v: visp._visp.core.RowVector, c: int, ncols: int) -> None
Construct a row vector from a part of an input row vector v .
The sub-vector starting from v[c] element and ending on v[c+ncols-1] element is used to initialize the constructed row vector.
Note
See init()
- Parameters:
- v
Input row vector used for initialization.
- c
column index in v that corresponds to the first element of the row vector to construct.
- ncols
Number of columns of the constructed row vector.
__init__(self: visp._visp.core.RowVector, M: visp._visp.core.Matrix) -> None
__init__(self: visp._visp.core.RowVector, M: visp._visp.core.Matrix, i: int) -> None
Constructor that creates a row vector corresponding to row i of matrix M .
__init__(self: visp._visp.core.RowVector, v: list[float]) -> None
__init__(self: visp._visp.core.RowVector, v: list[float]) -> None
__init__(self: visp._visp.core.RowVector, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.RowVector, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a row vector by copying a 1D numpy array.
- Parameters:
- np_array
The numpy 1D array to copy.
- __isub__(self, v: visp._visp.core.RowVector) visp._visp.core.RowVector ¶
Operator that allows to subtract two row vectors that have the same size.
- __itruediv__(self, x: float) visp._visp.core.RowVector ¶
Operator that allows to divide each element of a row vector by a scalar.
vpRowVector v(3); v[0] = 8; v[1] = 4; v[2] = 2; // v is equal to : [8 4 2] v /= 2; // v is equal to : [4 2 1]
- __mul__(*args, **kwargs)¶
Overloaded function.
__mul__(self: visp._visp.core.RowVector, x: visp._visp.core.ColVector) -> float
Multiply a row vector by a column vector.
- Parameters:
- x
Column vector.
- Returns:
A scalar.
__mul__(self: visp._visp.core.RowVector, M: visp._visp.core.Matrix) -> visp._visp.core.RowVector
Multiply a row vector by a matrix.
- Parameters:
- M
Matrix.
- Returns:
The resulting row vector.
__mul__(self: visp._visp.core.RowVector, x: float) -> visp._visp.core.RowVector
Operator that allows to multiply each element of a row vector by a scalar.
vpRowVector v(3); v[0] = 1; v[1] = 2; v[2] = 3; vpRowVector w = v * 3; // v is unchanged // w is now equal to : [3 6 9]
- Parameters:
- x
The scalar.
- Returns:
The row vector multiplied by the scalar. The current row vector (*this) is unchanged.
- __ne__(self, v: visp._visp.core.RowVector) bool ¶
- __neg__(self) visp._visp.core.RowVector ¶
Operator that allows to negate all the row vector elements.
vpRowVector r(3, 1); // r contains [1 1 1] vpRowVector v = -r; // v contains [-1 -1 -1]
- __setitem__(*args, **kwargs)¶
Overloaded function.
__setitem__(self: visp._visp.core.RowVector, arg0: int, arg1: float) -> None
__setitem__(self: visp._visp.core.RowVector, arg0: slice, arg1: float) -> None
__setitem__(self: visp._visp.core.RowVector, arg0: slice, arg1: numpy.ndarray[numpy.float64]) -> None
- __sub__(self, v: visp._visp.core.RowVector) visp._visp.core.RowVector ¶
Operator that allows to subtract to row vectors that have the same size.
- __truediv__(self, x: float) visp._visp.core.RowVector ¶
Operator that allows to divide each element of a row vector by a scalar.
vpRowVector v(3); v[0] = 8; v[1] = 4; v[2] = 2; vpRowVector w = v / 2; // v is equal to : [8 4 2] // w is 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
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, mode: str) -> visp._visp.core.ArrayDouble2D
conv2(M: visp._visp.core.ArrayDouble2D, kernel: visp._visp.core.ArrayDouble2D, res: visp._visp.core.ArrayDouble2D, mode: str) -> None
- deg2rad(self) None ¶
Convert a column vector containing angles in degrees into radians.
Note
See rad2deg()
- extract(self, c: int, rowsize: int) visp._visp.core.RowVector ¶
Extract a sub-row vector from a row vector.
vpRowVector r1; for (unsigned int i=0; i<4; ++i) r1.stack(i); // r1 is equal to [0 1 2 3] vpRowVector r2 = r1.extract(1, 3); // r2 is equal to [1 2 3]
- frobeniusNorm(self) float ¶
Compute and return the Frobenius norm \(||v|| = \sqrt{ \sum{v_{i}^2}}\) .
- Returns:
The Frobenius norm if the vector is initialized, 0 otherwise.
- hadamard(*args, **kwargs)¶
Overloaded function.
hadamard(self: visp._visp.core.RowVector, v: visp._visp.core.RowVector) -> visp._visp.core.RowVector
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
- init(self, v: visp._visp.core.RowVector, c: int, ncols: int) None ¶
Initialize the row vector from a part of an input row vector v .
The sub-vector starting from v[c] element and ending on v[c+ncols-1] element is used to initialize the constructed row vector.
The following code shows how to use this function:
#include <visp3/core/vpRowVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRowVector v(4); int val = 0; for(size_t i=0; i<v.getCols(); i++) { v[i] = val++; } std::cout << "v: " << v << std::endl; vpRowVector w; w.init(v, 1, 2); std::cout << "w: " << w << 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.RowVector, i: int, v: visp._visp.core.RowVector) -> None
Insert a row vector.The following example shows how to use this function:
#include <visp3/core/vpRowVector.h> #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpRowVector v(4); for (unsigned int i=0; i < v.size(); i++) v[i] = i; std::cout << "v: " << v << std::endl; vpRowVector w(2); for (unsigned int i=0; i < w.size(); i++) w[i] = i+10; std::cout << "w: " << w << std::endl; v.insert(1, w); std::cout << "v: " << v << 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
Row vector to insert.
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None
insert(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, r: int, c: int) -> visp._visp.core.ArrayDouble2D
- static insertStatic(A: visp._visp.core.ArrayDouble2D, B: visp._visp.core.ArrayDouble2D, C: visp._visp.core.ArrayDouble2D, r: int, c: int) None ¶
- static mean(v: visp._visp.core.RowVector) float ¶
Compute the mean value of all the elements of the vector.
- static median(v: visp._visp.core.RowVector) float ¶
Compute the median value of all the elements of the vector.
- normalize(*args, **kwargs)¶
Overloaded function.
normalize(self: visp._visp.core.RowVector) -> visp._visp.core.RowVector
Normalise the vector modifying the vector as:
\[{\bf x} = \frac{{\bf x}}{\sqrt{\sum_{i=1}^{n}x^2_i}} \]where \(x_i\) is an element of the row vector \(\bf x\) .
normalize(self: visp._visp.core.RowVector, x: visp._visp.core.RowVector) -> visp._visp.core.RowVector
Normalize the vector given as input parameter and return the normalized vector:
\[{\bf x} = \frac{{\bf x}}{\sqrt{\sum_{i=1}^{n}x^2_i}} \]where \(x_i\) is an element of the row vector \(\bf x\) .
- 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.RowVector, s: std::ostream, length: int, intro: str = 0) int ¶
Pretty print a row 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 row 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) None ¶
Convert a column vector containing angles in radians into degrees.
Note
See deg2rad()
- reshape(*args, **kwargs)¶
Overloaded function.
reshape(self: visp._visp.core.RowVector, M: visp._visp.core.Matrix, nrows: int, ncols: int) -> None
Reshape the row vector in a matrix.The following example shows how to use this method.
#include <visp3/core/vpRowVector.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; vpRowVector row = mat.stackRows(); std::cout << "row vector: " << row << std::endl; vpMatrix remat = row.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 row vector: 1 2 3 4 5 6 7 8 9 10 11 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.RowVector, nrows: int, ncols: int) -> visp._visp.core.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 resulting matrix.
reshape(self: visp._visp.core.ArrayDouble2D, nrows: int, ncols: int) -> None
- resize(*args, **kwargs)¶
Overloaded function.
resize(self: visp._visp.core.RowVector, i: int, flagNullify: bool = true) -> None
Modify the size of the row vector.
- Parameters:
- i
Size of the vector. This value corresponds to the vector number of columns.
- flagNullify
If true, set the data to zero.
resize(self: visp._visp.core.RowVector, nrows: int, ncols: int, flagNullify: bool) -> None
Resize the row vector to a ncols-dimension vector. This function can only be used with nrows = 1.
- Parameters:
- nrows
Vector number of rows. This value should be set to 1.
- ncols
Vector number of columns. This value corresponds to the size of the vector.
- 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(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
save(filename: str, A: visp._visp.core.ArrayDouble2D, binary: bool = false, header: str = ) -> bool
- stack(*args, **kwargs)¶
Overloaded function.
stack(self: visp._visp.core.RowVector, d: float) -> None
Stack row vector with a new element at the end of the vector.
vpRowVector v(3, 1); // v is equal to [1 1 1] v.stack(-2); // v is equal to [1 1 1 -2]
Note
See stack(const vpRowVector &, const vpRowVector &)
Note
See stack(const vpRowVector &, const vpRowVector &, vpRowVector &)
- Parameters:
- d
Element to stack to the existing one.
stack(self: visp._visp.core.RowVector, v: visp._visp.core.RowVector) -> None
Stack row vectors.
vpRowVector v1(3, 1); // v1 is equal to [1 1 1] vpRowVector v2(2, 3); // v2 is equal to [3 3] v1.stack(v2); // v1 is equal to [1 1 1 3 3]
Note
See stack(const vpRowVector &, const double &)
Note
See stack(const vpRowVector &, const vpRowVector &)
Note
See stack(const vpRowVector &, const vpRowVector &, vpRowVector &)
- Parameters:
- v
Vector to stack to the existing one.
- static stackVectors(*args, **kwargs)¶
Overloaded function.
stackVectors(A: visp._visp.core.RowVector, B: visp._visp.core.RowVector) -> visp._visp.core.RowVector
Stack row vectors.
vpRowVector r1(3, 1); // r1 is equal to [1 1 1] vpRowVector r2(2, 3); // r2 is equal to [3 3] vpRowVector v; v = vpRowVector::stack(r1, r2); // v is equal to [1 1 1 3 3]
Note
See stack(const vpRowVector &)
Note
See stack(const vpRowVector &, const vpRowVector &, vpRowVector &)
- Parameters:
- A
Initial vector.
- B
Vector to stack at the end of A.
- Returns:
Stacked vector \([A B]\) .
stackVectors(A: visp._visp.core.RowVector, B: visp._visp.core.RowVector, C: visp._visp.core.RowVector) -> None
Stack row vectors.
vpRowVector r1(3, 1); // r1 is equal to [1 1 1] vpRowVector r2(2, 3); // r2 is equal to [3 3] vpRowVector v; vpRowVector::stack(r1, r2, v); // v is equal to [1 1 1 3 3]
Note
See stack(const vpRowVector &)
Note
See stack(const vpRowVector &, const vpRowVector &)
- Parameters:
- A
Initial vector.
- B
Vector to stack at the end of A.
- C
Resulting stacked vector \(C = [A B]\) .
- static stdev(v: visp._visp.core.RowVector, 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 row vector v(n).
- Returns:
The sum square value: \(\sum_{j=0}^{n} v_j\) .
- sumSquare(self) float ¶
Return the sum square of all the elements \(v_{i}\) of the row vector v(n).
- Returns:
The sum square value: \(\sum_{j=0}^{n} v_j^{2}\) .
- t(*args, **kwargs)¶
Overloaded function.
t(self: visp._visp.core.RowVector) -> visp._visp.core.ColVector
Transpose the row vector. The resulting vector becomes a column vector.
t(self: visp._visp.core.ArrayDouble2D) -> visp._visp.core.ArrayDouble2D
- transpose(*args, **kwargs)¶
Overloaded function.
transpose(self: visp._visp.core.RowVector) -> visp._visp.core.ColVector
Transpose the row vector. The resulting vector becomes a column vector.
Note
See t()
transpose(self: visp._visp.core.RowVector, v: visp._visp.core.ColVector) -> None
Transpose the row vector. The resulting vector v becomes a column vector.
Note
See t()
- static view(np_array: numpy.ndarray[numpy.float64]) visp._visp.core.RowVector ¶
Construct a row vector that is a view of a numpy array. When it is modified, the numpy array is also modified. It cannot be resized.
- Parameters:
- np_array: numpy.ndarray[numpy.float64]¶
The numpy array to copy.
-
__hash__ =
None
¶