Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 answer
81 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
56 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
85 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
52 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
116 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
71 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
  • 1
3 votes
0 answers
100 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
76 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
34 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
52 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
806 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
172 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
152 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
49 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
146 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
150 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
110 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
413 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
85 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,302
1 vote
0 answers
67 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,302
4 votes
4 answers
482 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
84 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,302
-1 votes
1 answer
464 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
95 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
  • 866
1 vote
0 answers
63 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
104 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
78 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
86 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
114 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
68 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
68 views

convert ID3DXMatrixStack to DirectXMath

Is it right it convert ID3DXMatrixStack to DirectXMath like that: ...
user avatar
  • 23
2 votes
0 answers
42 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,181
2 votes
1 answer
41 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,181
1 vote
0 answers
102 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,302
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,181
1 vote
0 answers
65 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,302
1 vote
1 answer
42 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,302
1 vote
2 answers
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
65 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
  • 121
3 votes
3 answers
77 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
286 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
109 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
162 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
63 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
200 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
2 votes
1 answer
61 views

Multiply a square matrix with only the diagonal and antidiagonal elements different from zero in vector [closed]

So I have a square matrix with the diagonal and antidiagonal elements different from zero in a vector vector<int> matrix = {1,2,3,4,5,6,7,8}; The matrix: <...
user avatar
0 votes
0 answers
56 views

Optimizing matrix vector multiplication with keyword "register" and unsafe pointer arithmetic

I know this piece of code is quite strange, but it does its job very well performance-wise , reducing the running time of a very computation intensive operation by 3 - 5 times without using a better ...
user avatar
0 votes
2 answers
242 views

Matrix Calculator program in C language. How to avoid redundancy [closed]

I am trying to make a program for matrix Calculator and have done this so far. I want to avoid iteration or replication of the statements in my code but I want to restrict using the pointers in this. ...
user avatar
0 votes
1 answer
53 views

Divide a 3D matrix into multiple smaller 3D matrix

I'm trying to build an extension method that will allow me to subdivide a huge array into much smaller ones. My current code is the following but it still takes about 2s to generate with an array of ...
user avatar

1
2 3 4 5
14