Matrix  0.1.0
Easy-to-use Scientific Computing library in/for C++
matrix_operations.hpp
1 #ifndef _matrix_operations_hpp_
2 #define _matrix_operations_hpp_
3 
4 #include <matrix_basic.hpp>
5 
6 class MatrixOp {
7  private:
8  Matrix cofactor(Matrix, Matrix, int, int);
9  Matrix adjoint(Matrix);
10  Matrix scalar_to_mat(Matrix, double);
11  Matrix vector_to_mat(Matrix, Matrix);
12 
13  public:
14  Matrix init(std::vector<std::vector<double>>);
15  Matrix init(std::vector<std::vector<std::string>>);
16  Matrix concatenate(Matrix, Matrix, std::string);
18  Matrix zeros(int, int);
19  Matrix ones(int, int);
20  Matrix eye(int);
21  double determinant(Matrix, int);
23  Matrix sum(Matrix, std::string);
24  Matrix mean(Matrix, std::string);
25  Matrix std(Matrix, std::string);
26  Matrix min(Matrix, std::string);
27  Matrix max(Matrix, std::string);
28  Matrix argmin(Matrix, std::string);
29  Matrix argmax(Matrix, std::string);
32  Matrix power(Matrix, double);
33  Matrix slice_select(Matrix, Matrix, double, int);
34  Matrix delete_(Matrix, int, std::string);
35  Matrix exp(Matrix);
36  Matrix log(Matrix);
37  Matrix abs(Matrix);
39  Matrix genfromtxt(std::string, char);
40 
41 } matrix;
42 
44 Matrix MatrixOp::genfromtxt(std::string filename, char delim) {
45  Matrix mat;
46  std::ifstream file(filename);
47  std::string line, cell;
48  std::vector<std::string> cells;
49 
50  while (std::getline(file, line)) {
51  std::stringstream ss(line);
52  while (std::getline(ss, cell, delim)) {
53  cells.push_back(cell);
54  }
55  mat.str_mat.push_back(cells);
56  cells.clear();
57  }
58 
59  return mat;
60 }
61 
63 Matrix MatrixOp::init(std::vector<std::vector<double>> vec) {
64  Matrix result;
65  result.double_mat = vec;
66  result.to_string();
67  return result;
68 }
69 
71 Matrix MatrixOp::init(std::vector<std::vector<std::string>> vec) {
72  Matrix result;
73  result.str_mat = vec;
74  result.to_double();
75  return result;
76 }
77 
79 Matrix MatrixOp::concatenate(Matrix mat1, Matrix mat2, std::string dim) {
80  if (dim == "column") {
81  if (mat1.row_length() != mat2.row_length())
82  assert(("The Matrix objects should be of compatible dimensions", false));
83  for (int i = 0; i < mat1.row_length(); i++) {
84  mat1.str_mat[i].insert(mat1.str_mat[i].end(), mat2.str_mat[i].begin(),
85  mat2.str_mat[i].end());
86  }
87  } else if (dim == "row") {
88  if (mat1.col_length() != mat2.col_length())
89  assert(("The Matrix objects should be of compatible dimensions", false));
90  mat1.str_mat.insert(mat1.str_mat.end(), mat2.str_mat.begin(), mat2.str_mat.end());
91 
92  } else {
93  assert(("Concatenate dimension wrong", false));
94  }
95  if (mat1.if_double) {
96  mat1.to_double();
97  }
98  return mat1;
99 }
100 
103  bool error = (mat1.if_double) && (mat2.if_double);
104  if (!error)
105  assert(("The Matrix should be first converted to double using to_double() method", error));
106 
107  if (mat1.col_length() != mat2.row_length())
108  assert(("The Matrix objects should be of compatible dimensions", false));
109 
110  Matrix mat;
111  for (int i = 0; i < mat1.row_length(); i++) {
112  std::vector<double> row;
113  for (int j = 0; j < mat2.col_length(); j++) {
114  row.push_back(0);
115  }
116  mat.double_mat.push_back(row);
117  }
118  for (unsigned long int i = 0; i < mat1.row_length(); i++) {
119  for (unsigned long int j = 0; j < mat2.col_length(); j++) {
120  for (unsigned long int k = 0; k < mat2.row_length(); k++) {
121  mat.double_mat[i][j] += (mat1.double_mat[i][k] * mat2.double_mat[k][j]);
122  }
123  }
124  }
125  mat.to_string();
126  return mat;
127 }
128 
130 Matrix MatrixOp::zeros(int row, int col) {
131  Matrix result;
132  std::vector<std::string> vec(col, std::to_string(0));
133  std::vector<std::vector<std::string>> mat(row, vec);
134  result.str_mat = mat;
135  result.to_double();
136  return result;
137 }
138 
140 Matrix MatrixOp::ones(int row, int col) {
141  Matrix result;
142  std::vector<std::string> vec(col, std::to_string(1));
143  std::vector<std::vector<std::string>> mat(row, vec);
144  result.str_mat = mat;
145  result.to_double();
146  return result;
147 }
148 
151  Matrix result = zeros(size, size);
152  for (int i = 0; i < size; i++) {
153  result.str_mat[i][i] = "1";
154  result.double_mat[i][i] = 1;
155  }
156  return result;
157 }
158 
160 double MatrixOp::determinant(Matrix mat, int n) {
161  bool error = mat.if_double;
162  if (!error)
163  assert(("The Matrix should be first converted to double using to_double() method", error));
164 
165  if (mat.row_length() != mat.col_length())
166  assert(("The Matrix must be a square matrix", false));
167 
168  double D = 0;
169  if (n == 1)
170  return mat.double_mat[0][0];
171 
172  int sign = 1;
173  Matrix temp = zeros(n, n);
174 
175  for (int f = 0; f < n; f++) {
176  temp = cofactor(mat, temp, 0, f);
177  D += sign * mat.double_mat[0][f] * determinant(temp, n - 1);
178  sign = -sign;
179  }
180 
181  return D;
182 }
183 
186  bool error = mat.if_double;
187  if (!error)
188  assert(("The Matrix should be first converted to double using to_double() method", error));
189 
190  if (mat.row_length() != mat.col_length())
191  assert(("The Matrix must be a square matrix", false));
192  double det = determinant(mat, mat.col_length());
193  if (det == 0)
194  assert(("The Matrix is singular", false));
195 
196  Matrix adj = adjoint(mat);
197  Matrix result = adj / det;
198  return result;
199 }
200 
202 Matrix MatrixOp::sum(Matrix mat, std::string dim) {
203  bool error = mat.if_double;
204  if (!error)
205  assert(("The Matrix should be first converted to double using to_double() method", error));
206 
207  Matrix result;
208  if (dim == "column") {
209  result = zeros(1, mat.col_length());
210  for (int i = 0; i < mat.row_length(); i++) {
211  for (int j = 0; j < mat.col_length(); j++) {
212  result(0, j) = result(0, j) + mat(i, j);
213  result(0, j);
214  }
215  }
216  } else if (dim == "row") {
217  result = zeros(mat.row_length(), 1);
218  for (int i = 0; i < mat.col_length(); i++) {
219  for (int j = 0; j < mat.row_length(); j++) {
220  result(j, 0) = result(j, 0) + mat(j, i);
221  result(j, 0);
222  }
223  }
224  } else {
225  assert(("Second parameter 'dimension' wrong", false));
226  }
227  return result;
228 }
229 
231 Matrix MatrixOp::mean(Matrix mat, std::string dim) {
232  bool error = mat.if_double;
233  if (!error)
234  assert(("The Matrix should be first converted to double using to_double() method", error));
235 
236  Matrix result;
237  if (dim == "column") {
238  int n = mat.row_length();
239  result = sum(mat, dim) / n;
240  } else if (dim == "row") {
241  int n = mat.col_length();
242  result = sum(mat, dim) / n;
243  } else {
244  assert(("Second parameter 'dimension' wrong", false));
245  }
246  return result;
247 }
248 
250 Matrix MatrixOp::std(Matrix mat, std::string dim) {
251  bool error = mat.if_double;
252  if (!error)
253  assert(("The Matrix should be first converted to double using to_double() method", error));
254 
255  Matrix result;
256  if (dim == "column") {
257  int n = mat.row_length();
258  Matrix mean = sum(mat, dim) / n;
259  Matrix temp = mat - mean;
260  result = sum((temp * temp), dim) / n;
261  } else if (dim == "row") {
262  int n = mat.col_length();
263  Matrix mean = sum(mat, dim) / n;
264  Matrix temp = mat - mean;
265  result = sum((temp * temp), dim) / n;
266  } else {
267  assert(("Second parameter 'dimension' wrong", false));
268  }
269  return result;
270 }
271 
273 Matrix MatrixOp::min(Matrix mat, std::string dim) {
274  bool error = mat.if_double;
275  if (!error)
276  assert(("The Matrix should be first converted to double using to_double() method", error));
277 
278  if (dim == "column") {
279  std::vector<double> min_indices;
280  for (int i = 0; i < mat.col_length(); i++) {
281  std::vector<double> vec = mat.get_col(i);
282  min_indices.push_back(*std::min_element(vec.begin(), vec.end()));
283  }
284  std::vector<std::vector<double>> res;
285  res.push_back(min_indices);
286  return matrix.init(res);
287 
288  } else if (dim == "row") {
289  std::vector<double> temp;
290  std::vector<std::vector<double>> min_indices;
291  for (int i = 0; i < mat.row_length(); i++) {
292  std::vector<double> vec = mat.get_row(i);
293  temp.push_back(*std::min_element(vec.begin(), vec.end()));
294  min_indices.push_back(temp);
295  temp.clear();
296  }
297  return matrix.init(min_indices);
298 
299  } else {
300  assert(("Second parameter 'dimension' wrong", false));
301  }
302 }
303 
305 Matrix MatrixOp::max(Matrix mat, std::string dim) {
306  bool error = mat.if_double;
307  if (!error)
308  assert(("The Matrix should be first converted to double using to_double() method", error));
309 
310  if (dim == "column") {
311  std::vector<double> max_indices;
312  for (int i = 0; i < mat.col_length(); i++) {
313  std::vector<double> vec = mat.get_col(i);
314  max_indices.push_back(*std::max_element(vec.begin(), vec.end()));
315  }
316  std::vector<std::vector<double>> res;
317  res.push_back(max_indices);
318  return matrix.init(res);
319 
320  } else if (dim == "row") {
321  std::vector<double> temp;
322  std::vector<std::vector<double>> max_indices;
323  for (int i = 0; i < mat.row_length(); i++) {
324  std::vector<double> vec = mat.get_row(i);
325  temp.push_back(*std::max_element(vec.begin(), vec.end()));
326  max_indices.push_back(temp);
327  temp.clear();
328  }
329  return matrix.init(max_indices);
330 
331  } else {
332  assert(("Second parameter 'dimension' wrong", false));
333  }
334 }
335 
337 Matrix MatrixOp::argmin(Matrix mat, std::string dim) {
338  bool error = mat.if_double;
339  if (!error)
340  assert(("The Matrix should be first converted to double using to_double() method", error));
341 
342  if (dim == "column") {
343  std::vector<double> min_indices;
344  for (int i = 0; i < mat.col_length(); i++) {
345  std::vector<double> vec = mat.get_col(i);
346  min_indices.push_back(std::min_element(vec.begin(), vec.end()) - vec.begin());
347  }
348  std::vector<std::vector<double>> res;
349  res.push_back(min_indices);
350  return matrix.init(res);
351 
352  } else if (dim == "row") {
353  std::vector<double> temp;
354  std::vector<std::vector<double>> min_indices;
355  for (int i = 0; i < mat.row_length(); i++) {
356  std::vector<double> vec = mat.get_row(i);
357  temp.push_back(std::min_element(vec.begin(), vec.end()) - vec.begin());
358  min_indices.push_back(temp);
359  temp.clear();
360  }
361  return matrix.init(min_indices);
362 
363  } else {
364  assert(("Second parameter 'dimension' wrong", false));
365  }
366 }
367 
369 Matrix MatrixOp::argmax(Matrix mat, std::string dim) {
370  bool error = mat.if_double;
371  if (!error)
372  assert(("The Matrix should be first converted to double using to_double() method", error));
373 
374  if (dim == "column") {
375  std::vector<double> max_indices;
376  for (int i = 0; i < mat.col_length(); i++) {
377  std::vector<double> vec = mat.get_col(i);
378  max_indices.push_back(std::max_element(vec.begin(), vec.end()) - vec.begin());
379  }
380  std::vector<std::vector<double>> res;
381  res.push_back(max_indices);
382  return matrix.init(res);
383 
384  } else if (dim == "row") {
385  std::vector<double> temp;
386  std::vector<std::vector<double>> max_indices;
387  for (int i = 0; i < mat.row_length(); i++) {
388  std::vector<double> vec = mat.get_row(i);
389  temp.push_back(std::max_element(vec.begin(), vec.end()) - vec.begin());
390  max_indices.push_back(temp);
391  temp.clear();
392  }
393  return matrix.init(max_indices);
394 
395  } else {
396  assert(("Second parameter 'dimension' wrong", false));
397  }
398 }
399 
401  bool error = mat.if_double;
402  if (!error)
403  assert(("The Matrix should be first converted to double using to_double() method", error));
404 
405  std::vector<double> row;
406  std::vector<std::vector<double>> res;
407  for (int i = 0; i < mat.row_length(); i++) {
408  for (int j = 0; j < mat.col_length(); j++)
409  row.push_back(std::sqrt(mat.double_mat[i][j]));
410  res.push_back(row);
411  row.clear();
412  }
413 
414  return matrix.init(res);
415 }
416 
418  bool error1 = ((mat1.if_double) && (mat2.if_double));
419  if (!error1)
420  assert(("The Matrix objects should be first converted to double using to_double() method",
421  error1));
422 
423  if ((mat1.row_length() == mat2.row_length()) && (mat1.col_length() == mat2.col_length())) {
424  std::vector<double> row;
425  std::vector<std::vector<double>> res;
426  for (int i = 0; i < mat1.row_length(); i++) {
427  for (int j = 0; j < mat1.col_length(); j++)
428  row.push_back(std::pow(mat1.double_mat[i][j], mat2.double_mat[i][j]));
429  res.push_back(row);
430  row.clear();
431  }
432  return matrix.init(res);
433  } else if (((mat1.row_length() == mat2.row_length()) && (mat2.col_length() == 1)) ||
434  ((mat1.col_length() == mat2.col_length()) && (mat2.row_length() == 1))) {
435  mat2 = vector_to_mat(mat1, mat2);
436 
437  std::vector<double> row;
438  std::vector<std::vector<double>> res;
439  for (int i = 0; i < mat1.row_length(); i++) {
440  for (int j = 0; j < mat1.col_length(); j++)
441  row.push_back(std::pow(mat1.double_mat[i][j], mat2.double_mat[i][j]));
442  res.push_back(row);
443  row.clear();
444  }
445  return matrix.init(res);
446  } else {
447  assert(("The Matrix objects should be of compatible dimensions", false));
448  }
449 }
450 
451 Matrix MatrixOp::power(Matrix mat, double val) {
452  bool error = mat.if_double;
453  if (!error)
454  assert(("The Matrix should be first converted to double using to_double() method", error));
455 
456  Matrix mat_val = scalar_to_mat(mat, val);
457 
458  std::vector<double> row;
459  std::vector<std::vector<double>> res;
460  for (int i = 0; i < mat.row_length(); i++) {
461  for (int j = 0; j < mat.col_length(); j++)
462  row.push_back(std::pow(mat.double_mat[i][j], mat_val.double_mat[i][j]));
463  res.push_back(row);
464  row.clear();
465  }
466  return matrix.init(res);
467 }
468 
472 Matrix MatrixOp::slice_select(Matrix X, Matrix Y, double val, int col) {
473  X = X.slice(0, X.row_length(), col, col + 1);
474 
475  bool is_compatible = (X.row_length() == Y.row_length());
476  if (!is_compatible) {
477  assert(("The Matrix objects should be of same dimensions", is_compatible));
478  }
479  std::vector<std::vector<double>> res;
480  for (int i = 0; i < X.row_length(); i++) {
481  if (Y.double_mat[i][0] == val) {
482  res.push_back(X.get_row(i));
483  }
484  }
485  return init(res);
486 }
487 
489 Matrix MatrixOp::delete_(Matrix mat, int index, std::string dim) {
490  if (dim == "row") {
491  Matrix sl1 = mat.slice(0, index, 0, mat.col_length());
492  Matrix sl2 = mat.slice(index + 1, mat.row_length(), 0, mat.col_length());
493 
494  if (sl1.row_length() == 0)
495  return sl2;
496  if (sl2.row_length() == 0)
497  return sl1;
498  return concatenate(sl1, sl2, "row");
499  } else if (dim == "column") {
500  Matrix sl1 = mat.slice(0, mat.row_length(), 0, index);
501  Matrix sl2 = mat.slice(0, mat.row_length(), index + 1, mat.col_length());
502 
503  if (sl1.col_length() == 0)
504  return sl2;
505  if (sl2.col_length() == 0)
506  return sl1;
507  return concatenate(sl1, sl2, "column");
508  } else
509  assert(("Second parameter 'dimension' wrong", false));
510 }
511 
514  bool error1 = mat.if_double;
515  if (!error1)
516  assert(("The Matrix should be first converted to double using to_double() method", error1));
517 
518  std::vector<double> row;
519  std::vector<std::vector<double>> res;
520 
521  for (int i = 0; i < mat.row_length(); i++) {
522  for (int j = 0; j < mat.col_length(); j++)
523  row.push_back(std::exp(mat.double_mat[i][j]));
524  res.push_back(row);
525  row.clear();
526  }
527 
528  return init(res);
529 }
530 
533  bool error1 = mat.if_double;
534  if (!error1)
535  assert(("The Matrix should be first converted to double using to_double() method", error1));
536 
537  std::vector<double> row;
538  std::vector<std::vector<double>> res;
539 
540  for (int i = 0; i < mat.row_length(); i++) {
541  for (int j = 0; j < mat.col_length(); j++)
542  row.push_back(std::log(mat.double_mat[i][j]));
543  res.push_back(row);
544  row.clear();
545  }
546 
547  return init(res);
548 }
549 
552  bool error1 = mat.if_double;
553  if (!error1)
554  assert(("The Matrix should be first converted to double using to_double() method", error1));
555 
556  std::vector<double> row;
557  std::vector<std::vector<double>> res;
558 
559  for (int i = 0; i < mat.row_length(); i++) {
560  for (int j = 0; j < mat.col_length(); j++)
561  row.push_back(std::abs(mat.double_mat[i][j]));
562  res.push_back(row);
563  row.clear();
564  }
565 
566  return init(res);
567 }
568 
571  bool error1 = mat.if_double;
572  if (!error1)
573  assert(("The Matrix should be first converted to double using to_double() method", error1));
574 
575  std::vector<double> row;
576  std::vector<std::vector<double>> res;
577 
578  for (int i = 0; i < mat.row_length(); i++) {
579  for (int j = 0; j < mat.col_length(); j++)
580  row.push_back(1 / mat.double_mat[i][j]);
581  res.push_back(row);
582  row.clear();
583  }
584 
585  return init(res);
586 }
587 
588 // Helper methods
589 
591 Matrix MatrixOp::cofactor(Matrix mat, Matrix temp, int p, int q) {
592  int i = 0, j = 0;
593  for (int row = 0; row < mat.row_length(); row++) {
594  for (int col = 0; col < mat.col_length(); col++) {
595  if (row != p && col != q) {
596  temp.double_mat[i][j++] = mat.double_mat[row][col];
597  if (j == mat.col_length() - 1) {
598  j = 0;
599  i++;
600  }
601  }
602  }
603  }
604  temp.to_string();
605  return temp;
606 }
607 
609 Matrix MatrixOp::adjoint(Matrix mat) {
610  Matrix result = zeros(mat.row_length(), mat.col_length());
611 
612  if (mat.col_length() == 1) {
613  result.double_mat[0][0] = 1;
614  return result;
615  }
616 
617  int sign = 1;
618  Matrix temp = zeros(mat.row_length(), mat.col_length());
619 
620  for (int i = 0; i < mat.row_length(); i++) {
621  for (int j = 0; j < mat.col_length(); j++) {
622  temp = cofactor(mat, temp, i, j);
623  sign = ((i + j) % 2 == 0) ? 1 : -1;
624  result.double_mat[j][i] = (sign) * (determinant(temp, temp.col_length() - 1));
625  }
626  }
627 
628  return result;
629 }
630 
631 Matrix MatrixOp::scalar_to_mat(Matrix mat, double val) {
632  std::vector<std::string> row(mat.col_length(), std::to_string(val));
633  std::vector<std::vector<std::string>> res(mat.row_length(), row);
634 
635  return init(res);
636 }
637 
638 Matrix MatrixOp::vector_to_mat(Matrix mat, Matrix vec) {
639  std::vector<std::string> row;
640  std::vector<std::vector<std::string>> res;
641  if (mat.row_length() == vec.row_length()) {
642  for (int i = 0; i < mat.row_length(); i++) {
643  row.assign(mat.col_length(), vec.str_mat[i][0]);
644  res.push_back(row);
645  row.clear();
646  }
647  } else if (mat.col_length() == vec.col_length()) {
648  for (int i = 0; i < mat.row_length(); i++) {
649  res.push_back(vec.str_mat[0]);
650  }
651  }
652 
653  return init(res);
654 }
655 
656 #endif /* _matrix_operations_hpp_ */
MatrixOp::log
Matrix log(Matrix)
Method to calculate natural logarithm of all elements in the Matrix object.
Definition: matrix_operations.hpp:532
MatrixOp::sqrt
Matrix sqrt(Matrix)
Definition: matrix_operations.hpp:400
Matrix::slice
Matrix slice(int, int, int, int)
Method to slice a Matrix object The method will return a Matrix object whose dimensions will be (row_...
Definition: matrix_basic.hpp:150
Matrix::if_double
bool if_double
Definition: matrix_basic.hpp:21
MatrixOp::eye
Matrix eye(int)
Method to create an identity Matrix.
Definition: matrix_operations.hpp:150
Matrix::double_mat
std::vector< std::vector< double > > double_mat
Definition: matrix_basic.hpp:19
MatrixOp::std
Matrix std(Matrix, std::string)
Method to calculate the standard deviation over an axis of a Matrix.
Definition: matrix_operations.hpp:250
MatrixOp::matmul
Matrix matmul(Matrix, Matrix)
Method to calculate matrix multiplication.
Definition: matrix_operations.hpp:102
MatrixOp::exp
Matrix exp(Matrix)
Method to calculate exponential of all elements in the Matrix object.
Definition: matrix_operations.hpp:513
MatrixOp::concatenate
Matrix concatenate(Matrix, Matrix, std::string)
Method to concatenate/join two Matrix objects.
Definition: matrix_operations.hpp:79
MatrixOp::genfromtxt
Matrix genfromtxt(std::string, char)
Method to read a csv file and return a Matrix object.
Definition: matrix_operations.hpp:44
Matrix::col_length
int col_length()
Method to return the number of columns.
Definition: matrix_basic.hpp:95
MatrixOp
Definition: matrix_operations.hpp:6
MatrixOp::power
Matrix power(Matrix, Matrix)
Definition: matrix_operations.hpp:417
MatrixOp::argmin
Matrix argmin(Matrix, std::string)
Method to get the index of minimum value along an axis.
Definition: matrix_operations.hpp:337
MatrixOp::ones
Matrix ones(int, int)
Method to create an Matrix of all elements 1.
Definition: matrix_operations.hpp:140
Matrix::str_mat
std::vector< std::vector< std::string > > str_mat
Definition: matrix_basic.hpp:20
MatrixOp::slice_select
Matrix slice_select(Matrix, Matrix, double, int)
In Y, find list of indices of element whose value is val, then return the col'th column of the Matrix...
Definition: matrix_operations.hpp:472
MatrixOp::delete_
Matrix delete_(Matrix, int, std::string)
Method to delete a row or column of a Matrix object.
Definition: matrix_operations.hpp:489
MatrixOp::min
Matrix min(Matrix, std::string)
Method to get the minimum value along an axis.
Definition: matrix_operations.hpp:273
MatrixOp::max
Matrix max(Matrix, std::string)
Method to get the maximum value along an axis.
Definition: matrix_operations.hpp:305
MatrixOp::argmax
Matrix argmax(Matrix, std::string)
Method to get the index of maximum value along an axis.
Definition: matrix_operations.hpp:369
MatrixOp::reciprocal
Matrix reciprocal(Matrix)
Method to calculate reciprocal of all elements in the Matrix object.
Definition: matrix_operations.hpp:570
Matrix::to_double
void to_double()
Method convert the elements of a Matrix from std::string to double.
Definition: matrix_basic.hpp:191
Matrix::get_row
std::vector< double > get_row(int)
Method to return a row of the matrix in the form of a vector.
Definition: matrix_basic.hpp:61
MatrixOp::sum
Matrix sum(Matrix, std::string)
Method to calculate the sum over an axis of a Matrix.
Definition: matrix_operations.hpp:202
Matrix::to_string
void to_string()
Method convert the elements of a Matrix from double to std::string.
Definition: matrix_basic.hpp:204
Matrix::get_col
std::vector< double > get_col(int)
Method to return a column of the matrix in the form of a vector.
Definition: matrix_basic.hpp:78
MatrixOp::abs
Matrix abs(Matrix)
Method to get absolute value of all elements in the Matrix object.
Definition: matrix_operations.hpp:551
MatrixOp::mean
Matrix mean(Matrix, std::string)
Method to calculate the mean over an axis of a Matrix.
Definition: matrix_operations.hpp:231
Matrix
Definition: matrix_basic.hpp:13
MatrixOp::inverse
Matrix inverse(Matrix)
Method to calculate the Inverse of a Matrix.
Definition: matrix_operations.hpp:185
MatrixOp::determinant
double determinant(Matrix, int)
Method to calculate the Determinant of a Matrix.
Definition: matrix_operations.hpp:160
MatrixOp::init
Matrix init(std::vector< std::vector< double >>)
Method to initialize values of a Matrix object using a 2D vector.
Definition: matrix_operations.hpp:63
MatrixOp::zeros
Matrix zeros(int, int)
Method to create an Matrix of all elements 0.
Definition: matrix_operations.hpp:130
Matrix::row_length
int row_length()
Method to return the number of rows.
Definition: matrix_basic.hpp:98