Questions tagged [matrix]

In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. The individual items in a matrix are called its elements or entries.

Filter by
Sorted by
Tagged with
2 votes
0 answers
30 views

S_n covariance calculation function

I am trying to understand the estimator proposed in "Multidimensional outlier detection and robust estimation using Sn covariance". I wrote the code in a basic line-by-line form which is ...
user avatar
5 votes
2 answers
204 views

A matrix class using const members

I've long used a simple matrix class with a vector and rows/cols for the shape. But I've always disliked getters even when necessary to prevent exposing invariants. Then came c++20 which provided the ...
user avatar
  • 153
2 votes
0 answers
67 views

Cosine similarity calculation in Rust, which is slower than NumPy

I'm running this in release mode. Currently, the following function takes around 6.7 seconds to run on my computer vs 3.7 seconds on Python. I know that Numpy is just calling to C, but I'm trying to ...
user avatar
0 votes
1 answer
43 views

Approximation of the multiplicative matrix inverse (linalg.inv ())

I am trying to compute the multiplicative inverse of a large matrix (~ >40,000x40,000). This can be done with e.g. numpy.linalg.inv or ...
user avatar
  • 103
2 votes
1 answer
91 views

Returning all divisors of a number as a matrix with N X 2 dimensions

I have developed a class structure with methods to return a matrix from a single input array. The objective is to insert the middle value of the array so 2n remains ...
user avatar
1 vote
2 answers
58 views

Validator for 0/1 entries in a matrix

I build a function(A kind of puzzle) that counts from a matrix the number of valid count (Explanation below). The matrix is ​​made up of 0,1. Input- a matrix- list of lists row number column number ...
user avatar
  • 13
5 votes
1 answer
94 views

С++: Find max element from section in matrix

I'm a newbie in programming. Could you please check my code and give any refactoring ideas, tips, etc... how it can be improved. I wrote a code to perform the following task: Find in randomly filled ...
user avatar
3 votes
0 answers
54 views

Accelerating this stacked matrix-matrix product in OpenCL

I am trying to compute a matrix-matrix product of N stacked complex double N x N matrices. For simplicity, I assume N = 512. I have written code in C++ parallelized with OMP and using OpenBLAS for the ...
user avatar
  • 31
3 votes
0 answers
191 views

Return a 2D matrix from a C++ function in Python: ctypes versus pybind11

I found two ways in which I can use a custom C++ function (returning a 2D matrix) in Python. One approach that uses the Python module ctypes and another that uses the Python module pybind11. Approach ...
user avatar
1 vote
1 answer
74 views

multiply matrices

I wrote a program that calculates the multiplication of two matrices (of compatible dimensions) where each element of the resulting matrix is ​​calculated by a separate thread. Each thread calculates ...
user avatar
  • 449
3 votes
0 answers
104 views

Two-dimensional arrays in C

I have a bit of trouble with two-dimensional arrays in C. I want to pass such an array to a function accepting a pointer to pointers. I figured no way of really passing the array itself. Furthermore, ...
user avatar
  • 31
0 votes
0 answers
79 views

Load license plate data from Excel

The code below gets data from an Excel spreadsheet and returns some values; this can take up to 15 minutes because the Excel has more than 15 columns and an average of 20,000 rows. ...
user avatar
  • 11
0 votes
1 answer
39 views

Function for inserting values in a nxn matrix by changing directions inside of it

I am relatively new to C++ and I had this task to solve, where you are given a number and you have to create an nxn array of integers, where you would have to continually switch directions (right, ...
user avatar
  • 1
0 votes
1 answer
58 views

Given a matrix return true if it contains the Identity matrix (by recursion)

I need to write recursive static method with given 3 parameters the method will return true if the sub matrix with the size of (int size) which the left corner is mat[x][x] is the identity matrix ...
user avatar
11 votes
3 answers
847 views

Matrix implementation

I am trying to implement an optimal and fast running matrix in C++. I need some review of the code and ideas on how to improve the code quality if it shall be. ...
user avatar
4 votes
1 answer
176 views

Minimize memory allocations while calculating the matrix representation of a Hamiltonian

I am writing a script using Julia (calling my functions from the REPL) to compute the matrix representation of certain Hamiltonian. After I run my script I see that the memory allocations count is ...
user avatar
5 votes
2 answers
162 views

Rotating a matrix clockwise by one element without any libraries (Python 3.9)

The question is as follows: Rotate an NxN matrix clockwise by one element and display the new matrix. For example, if ...
user avatar
  • 53
2 votes
1 answer
54 views

Python: Create submatrices from long/narrow table and save in HDF5

Hello dear StackExchange Community, I have written a small program which is doing the following. In short: it reads in a table in narrow format creates submatrices from it saves it in HDF5 format ...
user avatar
4 votes
3 answers
150 views

Barebones C++ Matrix class

I have implemented a C++ Matrix class using std::vector and a number for rows/cols. The implementation works decently from the QA I've done. I have implemented a Vector class as a derived class but I'...
user avatar
2 votes
0 answers
156 views

2d Grid - Iterating by Rows / Cells - Take #3

Edited with a bit more unit tests. Preface Following my second version: 2d Grid - Iterating by Rows / Cells - Take #2 I believe that I am now satisfied with this new version below. There is still one ...
user avatar
2 votes
2 answers
117 views

2d Grid - Iterating by Rows / Cells - Take #2

Preface Following my first POC version: 2d Grid - Iterating by Rows / Cells I have gained much more understanding, and present A new version A new version is ready, with templates and an attempt at ...
user avatar
6 votes
2 answers
465 views

Writing a C++ Matrix class

I am refreshing my C++ programming skills, and I'm currently reading the book C++ 17 by Ivor Horton. The idea is to code some naive implementations of numerical algorithms (Root finding, solving a ...
user avatar
  • 335
1 vote
1 answer
105 views

Calculate distances between two multi-dimensional arrays in Matlab

In question "Dictionary based non-local mean implementation in Matlab", the Manhattan distance between two three-dimensional structures can be calculated by ...
user avatar
  • 3,576
1 vote
0 answers
72 views

Dictionary based non-local mean implementation in Matlab

Given a dictionary including multiple X-Y pairs where X, Y are both three dimensional structure. dictionaryBasedNonlocalMean function return a ...
user avatar
  • 3,576
4 votes
4 answers
532 views

Make surrounding elements zero in a matrix, when you find a zero value

Please can you suggest a better / Optimized logic or code for the question. It has been asked that when you find a zero value in a matrix, make that element the sum of its upper, lower ,left, right ...
user avatar
3 votes
1 answer
89 views

Three-dimensional DCT spatial frequency components illustration

I am attempting to make three-dimensional discrete cosine transformation spatial frequency components illustration. The 3D cubes is used to present the level of each coefficient. The more bright the ...
user avatar
  • 3,576
-1 votes
1 answer
534 views

Find Passable Lanes in Rows and Columns

I have implemented the following question and looking forward for the reviews. Question Explanation : We have a two-dimensional board game involving snakes. The board has two types of squares on it: +...
user avatar
0 votes
0 answers
97 views

If maze has path

I have applied a DFS solution for to check finding path if exist from beginning point to the end point. OA: Given 2d array, check if there is path from one beginning point to given endpoint in the ...
user avatar
0 votes
0 answers
47 views

Vectorized code to find the position and length of runs of 1s in a bit matrix

I'm trying to write something like an adjusted run-length encoding for row-wise bit matrices. Specifically I want to "collapse" runs of 1s into the number of 1s in that run while maintaining ...
user avatar
  • 896
1 vote
0 answers
70 views

template Matrix class with Static or dynamic size

I started implementing the folowing Matrix class in order to get a better understanding of templates classes in general. For now, it lacks a lot of features, it does very basic things: addition ...
user avatar
  • 11
0 votes
2 answers
110 views

Given a 2d matrix with chars find the target string

I am looking for a simpler implementation of the following question. Could it get better? I am expecting the new solution via DFS again. Thanks. OA: Given a 2d matrix with chars and a target string. ...
user avatar
3 votes
1 answer
96 views

Find number of ways to traverse matrix of 0's and 1's

I solved a Daily Coding Challenge, but i suspect my code could be optimised. The challenge is the following: You are given an N by M matrix of 0s and 1s. Starting from the top left corner, how many ...
user avatar
0 votes
1 answer
99 views

Iterating 2d array

I have implemented a MatrixIt class to traverse a 2D array. Is it possible to make the code clearer and shorter? ...
user avatar
4 votes
0 answers
116 views

LeetCode 1632: Rank Transform of a Matrix in Rust

This is a problem-solving code for LeetCode 1632. Given an \$m \times n\$ matrix, return a new matrix answer where ...
user avatar
0 votes
0 answers
70 views

Transform inertia tensor

I am trying to translate book: Game Physics Engine Development by Ian Millington to DirectXMath and faced with the code wich transform inertia tensor. Is it right to convert code from book like that: ...
user avatar
  • 23
0 votes
0 answers
74 views

convert ID3DXMatrixStack to DirectXMath

Is it right it convert ID3DXMatrixStack to DirectXMath like that: ...
user avatar
  • 23
2 votes
0 answers
43 views

C++20 Ndim matrix, computing eigenvalues and eigenvectors

My C++20 N-dimensional matrix project now supports basic linear algebra operations: https://github.com/frozenca/Ndim-Matrix Today I want to get some reviews on computing eigenvalues and eigenvectors. ...
user avatar
  • 1,583
2 votes
1 answer
44 views

C++20 : Ndim Matrix, broadcasting, np.dot() and np.matmul()

I've improved my N-dimensional C++20 matrix project (C++20 : N-dimensional minimal Matrix class). Implemented general matrix addition/subtraction, elementwise multiplication/division, dot product, ...
user avatar
  • 1,583
1 vote
0 answers
106 views

Parallel 3D Discrete Cosine Transformation Implementation in Matlab

I am trying to implement 3D Discrete Cosine Transformation calculation in Matlab with parallel computing parfor. The formula of 3D Discrete Cosine Transformation is ...
user avatar
  • 3,576
7 votes
2 answers
1k views

C++20 : N-dimensional minimal Matrix class

I wrote a N-dim matrix (tensor) class, based on my previous 2D matrix implementation(2D Matrix in C++20 and Strassen's algorithm), accepting many helpful reviews from here. MatrixBase.h ...
user avatar
  • 1,583
1 vote
0 answers
68 views

3D Non-local Mean Algorithm in MATLAB

This is a follow-up question for GetNeighborhood function for 3D cells structure in MATLAB. Based on the existing 2D non-local algorithm, I am attempting to implement 3D non-local mean algorithm in ...
user avatar
  • 3,576
1 vote
1 answer
43 views

GetNeighborhood function for 3D cells structure in MATLAB

I am attempting to implement a GetNeighborhood function in order to get a specific region from inputCells by ...
user avatar
  • 3,576
1 vote
1 answer
1k views

Lo Shu Magic Square (Python)

I wrote a python program to find if a matrix is a magic square or not. It works, but I can't help feeling like I may have overcomplicated the solution. I have seen other implementations that were a ...
user avatar
  • 305
2 votes
0 answers
75 views

Rcpp sparse CSC matrix class

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
user avatar
  • 143
3 votes
3 answers
97 views

C string parser criticism

I have written a program to parse a string depending on the string the user provides. Any advise/criticism is appreciated. ...
user avatar
  • 403
2 votes
2 answers
336 views

Finding distance between vectors of matrices

So here is the problem: Given 2D numpy arrays 'a' and 'b' of sizes n×m and k×m respectively and one natural number 'p'. You need to find the distance(Euclidean) of the rows of the matrices 'a' and ...
user avatar
3 votes
1 answer
127 views

Implementation of the basic matrix operations for embedded application in C++

I have been developing a control software in C++ and for implementation of the control algorithms I need basic matrix operations like addition, subtraction, multiplication and multiplication by scalar....
user avatar
  • 375
0 votes
0 answers
196 views

Finding the Euclidean distance between the vectors of matrix a, and vector b

Here is the problem, Given a 2D numpy array 'a' of sizes n×m and a 1D numpy array 'b' of size m. You need to find the distance(Euclidean) of the 'b' vector from the rows of the 'a' matrix. Fill the ...
user avatar
2 votes
1 answer
64 views

Convert a matrix ("DataFrame") to printable string

While I understand that "V is a simple language," I find myself repeating a lot of stuff. For instance the whole first block, "measure column widths," could beautifully be ...
user avatar
5 votes
1 answer
224 views

Compile-time Matrix Class

Intended as a small project to test out various C++20 features, as well as learn a little bit more about matrices and their uses, I decided to implement a relatively simple matrix class. After ...
user avatar
  • 53

1
2 3 4 5
14