Row vector)

Source: Internet
Author: User

1. Line Vector class: DefinitionRow <Type>

2. Common typedef

rowvec = Row<double>frowvec = Row<float>cx_rowvec = Row<cx_double>cx_frowvec = Row<cx_float>urowvec = Row<uword>irowvec = Row<sword>

3. Create

Rowvec R1 = "1, 2, 3, 4"; rowvec r2 = initializer_list <double> {1, 2, 3, 4}; rowvec R3; // The row vector does not initialize R3 <1 <2 <3 <4; rowvec R4 (R1); double * ELEM = new double [4] {1, 2, 3, 4}; rowvec R5 (ELEM, 4); // This is to copy elements from the memory pointed to by the ELEM pointer, so it is safe rowvec R6 (ELEM, 4, false); // This is the memory directly pointed to by the ELEM pointer, therefore, it is necessary to ensure that ELEM points to the existence of V6 within its life cycle and is not used by others. // and the vector size cannot be directly or indirectly changed by rowvec R7 (ELEM, 4, false, false); // This is the memory directly pointed to by the ELEM pointer, so ensure that ELEM points to the memory within the life cycle of V6 is valid and not Used by another user // and the vector size can be reset. After the size is reset, the memory pointed to by ELEM is not used. Vector <double> E = {1, 2, 3, 4}; rowvec R8 (E); mat m = "1, 2, 3, 4;"; rowvec R9 (m); // If M is not a row vector, STD :: logic_error exception // R1, R2... r9 is the same row vector and all are (,) rowvec R10 = rowvec: Fixed <4> (); // create a fixed-size row vector, the vector size (number of elements) after creation cannot be changed. // Use a fixed row vector to calculate faster than the dynamically allocated rowvec R11 = rowvec: Fixed <4> (","); rowvec R12 = rowvec :: fixed <4> (); R12 <1 <2 <3 <4 ;//... similarly, you can use several constructors that you have previously used to specify the initial filling constructor rowvec v13 (4 ); // create a row vector rowvec V14 (4, fill: zeros) for four elements; // create a row vector for four elements. Each element is 0 rowvec V15 (4, fill: ones); // create a row vector of four elements. Each element is 1 rowvec V16 (4, fill: randu ); // create a row vector with four elements. Each element is a random number rowvec v17 (4, fill: randn) between [0, 1]. // create a row vector with four elements, each element is a random number with a normal/Gaussian distribution with an average value of 0 and a variance of 1.

4. row vector operations

V1.n _ Cols () // Number of columns v1.n _ rows () // number of rows, with a constant of 1v1 (0) // to access 0th elements, checks whether the elements are out of bounds and throws STD :: logic_error exception V1 [0] // access 0th elements, do not check whether cross-border v1.clear (); // clear the vector, the vector is changed to 0*1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.