0

I want to do all kinds of matrix operation like finding a sub-matrix and finding its index and multiplication using vectors but can't find proper syntax for that on the internet. Please let me know the correct syntax to transition from primitive data types to vectors.

sam
  • 1
  • 2
  • 1
    How many dimensions do you expect to be working in? vector-of-vector is almost always a very poor choice for matrices. Note that `vector` in C++ refers to a template container that provides a contiguous block of dynamically allocated memory. It is not really the same as the kind of vector you might be wishing to use for, say, 3D math. – paddy Apr 12 '21 at 05:08
  • Unless you have a lot of constraints, why not use a library to do the same? This is a relevant post : https://stackoverflow.com/questions/1380371/what-are-the-most-widely-used-c-vector-matrix-math-linear-algebra-libraries-a – Raviteja Narra Apr 12 '21 at 05:13
  • Vectors of vectors is not really a great way to represent matrices. Use a 1D vector. Use std::array of std::array only if your matrices are of a fixed known size. – n. 'pronouns' m. Apr 12 '21 at 05:20

1 Answers1

2

I suggest that you have a look at linear algrebra libraries, such as eigen, armadillo or lapack.

For armadillo you can find here an example on how to transform data form your structure to theirs.

Transforming or copying will take some time. Nevertheless, you will have a hard time creating a linear algebra library on your own, that will out-perform one of these libraries. Moreover, if you design your datastructure accordingly, you don't have to pay for this overhead.

schorsch312
  • 5,032
  • 4
  • 21
  • 47