ArrayDouble2D¶
- class ArrayDouble2D(*args, **kwargs)¶
Bases:
pybind11_object
Implementation of a generic 2D array used as base class for matrices and vectors.
This class implements a 2D array as a template class and all the basic functionalities common to matrices and vectors. More precisely:
concerning matrices, vpMatrix but also specific containers such as twist ( vpVelocityTwistMatrix and vpForceTwistMatrix ), homogeneous ( vpHomogeneousMatrix ), rotation ( vpRotationMatrix ) and homography ( vpHomography ) matrices inherit from vpArray2D<double> .
concerning vectors, vpColVector , vpRowVector but also specific containers describing the pose ( vpPoseVector ) and the rotation ( vpRotationVector ) inherit also from vpArray2D<double> .
The code below shows how to create a 2-by-3 array of doubles, set the element values and access them:
#include <visp3/code/vpArray2D.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpArray2D<float> a(2, 3); a[0][0] = -1; a[0][1] = -2; a[0][2] = -3; a[1][0] = 4; a[1][1] = 5.5; a[1][2] = 6; std::cout << "a:" << std::endl; for (unsigned int i = 0; i < a.getRows(); ++i) { for (unsigned int j = 0; j < a.getCols(); ++j) { std::cout << a[i][j] << " "; } std::cout << std::endl; } }
Once build, this previous code produces the following output:
a: -1 -2 -3 4 5.5 6
If ViSP is build with c++11 enabled, you can do the same using:
#include <visp3/code/vpArray2D.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpArray2D<float> a{ {-1, -2, -3}, {4, 5.5, 6.0f} }; std::cout << "a:\n" << a << std::endl; }
The array could also be initialized using operator=(const std::initializer_list< std::initializer_list< Type > > &)
#include <visp3/code/vpArray2D.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpArray2D<float> a; a = { {-1, -2, -3}, {4, 5.5, 6.0f} }; }
You can also use reshape() function:
#include <visp3/code/vpArray2D.h #ifdef ENABLE_VISP_NAMESPACE using namespace VISP_NAMESPACE_NAME; #endif int main() { vpArray2D<float> a{ -1, -2, -3, 4, 5.5, 6.0f }; a.reshape(2, 3); }
Overloaded function.
__init__(self: visp._visp.core.ArrayDouble2D) -> None
Basic constructor of a 2D array. Number of columns and rows are set to zero.
__init__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> None
Copy constructor of a 2D array.
__init__(self: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None
Constructor that initializes a 2D array with 0.
- Parameters:
- r
Array number of rows.
- c
Array number of columns.
__init__(self: visp._visp.core.ArrayDouble2D, r: int, c: int, val: float) -> None
Constructor that initialize a 2D array with val .
- Parameters:
- r
Array number of rows.
- c
Array number of columns.
- val
Each element of the array is set to val .
__init__(self: visp._visp.core.ArrayDouble2D, vec: list[float], r: int = 0, c: int = 0) -> None
Constructor that initialize a 2D array from a std::vector.
When c = 0, create a colum vector with dimension (data.size, 1)
When r = 0, create a row vector with dimension (1, data.size)
Otherwise create an array with dimension (r, c)
- Parameters:
- vec
Data used to initialize the 2D array.
- r
Array number of rows.
- c
Array number of columns.
__init__(self: visp._visp.core.ArrayDouble2D, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.ArrayDouble2D, nrows: int, ncols: int, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.ArrayDouble2D, lists: std::initializer_list<std::initializer_list<double> >) -> None
__init__(self: visp._visp.core.ArrayDouble2D, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a 2D ViSP array by copying a 2D numpy array.
- Parameters:
- np_array
The numpy array to copy.
Methods
Overloaded function.
Overloaded function.
Return the number of columns of the 2D array.
Return the array max value.
Return the array min value.
Return the number of rows of the 2D array.
- param m:
Second matrix;
Overloaded function.
Insert array B in array A at the given position.
Numpy view of the underlying array data.
Set the size of the array and initialize all the values to zero.
Overloaded function.
Save an array in a YAML-formatted file.
Return the number of elements of the 2D array.
Compute the transpose of the array.
Inherited Methods
Operators
__doc__
Overloaded function.
Overloaded function.
Overloaded function.
__module__
Overloaded function.
__repr__
Attributes
__annotations__
- __eq__(*args, **kwargs)¶
Overloaded function.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
__eq__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Equal to comparison operator of a 2D array.
- __getitem__(*args, **kwargs)¶
Overloaded function.
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: tuple[int, int]) -> float
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: int) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: slice) -> numpy.ndarray[numpy.float64]
__getitem__(self: visp._visp.core.ArrayDouble2D, arg0: tuple) -> numpy.ndarray[numpy.float64]
- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: visp._visp.core.ArrayDouble2D) -> None
Basic constructor of a 2D array. Number of columns and rows are set to zero.
__init__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> None
Copy constructor of a 2D array.
__init__(self: visp._visp.core.ArrayDouble2D, r: int, c: int) -> None
Constructor that initializes a 2D array with 0.
- Parameters:
- r
Array number of rows.
- c
Array number of columns.
__init__(self: visp._visp.core.ArrayDouble2D, r: int, c: int, val: float) -> None
Constructor that initialize a 2D array with val .
- Parameters:
- r
Array number of rows.
- c
Array number of columns.
- val
Each element of the array is set to val .
__init__(self: visp._visp.core.ArrayDouble2D, vec: list[float], r: int = 0, c: int = 0) -> None
Constructor that initialize a 2D array from a std::vector.
When c = 0, create a colum vector with dimension (data.size, 1)
When r = 0, create a row vector with dimension (1, data.size)
Otherwise create an array with dimension (r, c)
- Parameters:
- vec
Data used to initialize the 2D array.
- r
Array number of rows.
- c
Array number of columns.
__init__(self: visp._visp.core.ArrayDouble2D, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.ArrayDouble2D, nrows: int, ncols: int, list: std::initializer_list<double>) -> None
__init__(self: visp._visp.core.ArrayDouble2D, lists: std::initializer_list<std::initializer_list<double> >) -> None
__init__(self: visp._visp.core.ArrayDouble2D, np_array: numpy.ndarray[numpy.float64]) -> None
Construct a 2D ViSP array by copying a 2D numpy array.
- Parameters:
- np_array
The numpy array to copy.
- __ne__(*args, **kwargs)¶
Overloaded function.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
__ne__(self: visp._visp.core.ArrayDouble2D, A: visp._visp.core.ArrayDouble2D) -> bool
Not equal to comparison operator of a 2D array.
- 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 0x7fd02a412920>>
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 0x7fd02a42c580>>
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 0x7fd02a412920>>
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 0x7fd02a42c580>>
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”.
- hadamard(self, m: visp._visp.core.ArrayDouble2D) visp._visp.core.ArrayDouble2D ¶
- Parameters:
- m: visp._visp.core.ArrayDouble2D¶
Second matrix;
- Returns:
m1.hadamard(m2) The Hadamard product : \(m1 \circ m2 = (m1 \circ m2)_{i,j} = (m1)_{i,j} (m2)_{i,j}\)
- insert(*args, **kwargs)¶
Overloaded function.
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.
- numpy(self) numpy.ndarray[numpy.float64] ¶
Numpy view of the underlying array data. This numpy view can be used to directly modify the array.
- resize(self, 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: int¶
number of rows.
- ncols: int¶
number of column.
- flagNullify: bool = true¶
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_: bool = true¶
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.
- t(self) visp._visp.core.ArrayDouble2D ¶
Compute the transpose of the array.
- Returns:
vpArray2D<Type> C = A^T
-
__hash__ =
None
¶