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
4
votes
4answers
312 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 ...
3
votes
1answer
59 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 ...
-1
votes
1answer
34 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: +...
0
votes
0answers
88 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 ...
0
votes
0answers
39 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 ...
1
vote
0answers
42 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 ...
0
votes
1answer
73 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. ...
3
votes
1answer
41 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 ...
0
votes
1answer
51 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? ...
4
votes
0answers
102 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 ...
0
votes
0answers
58 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: ...
0
votes
0answers
26 views

Algorithm for efficient creation of submatrices from original matrix

I wrote this code to simply visualise what happens to an image when it gets put through repeated convolutional filters is a CNN. The code works fine and produces the expected result but the it is also ...
0
votes
0answers
48 views

convert ID3DXMatrixStack to DirectXMath

Is it right it convert ID3DXMatrixStack to DirectXMath like that: ...
1
vote
0answers
36 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. ...
1
vote
0answers
28 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, ...
1
vote
0answers
73 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 ...
7
votes
2answers
865 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 ...
1
vote
0answers
51 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 ...
1
vote
1answer
41 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 ...
1
vote
1answer
185 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 ...
2
votes
0answers
53 views

Rcpp sparse CSC matrix class

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
3
votes
3answers
69 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. ...
2
votes
2answers
68 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 ...
3
votes
1answer
65 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....
0
votes
0answers
44 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 ...
2
votes
1answer
57 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 ...
5
votes
1answer
78 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 ...
2
votes
1answer
53 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: <...
0
votes
0answers
46 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 ...
0
votes
2answers
152 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. ...
0
votes
1answer
44 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 ...
3
votes
1answer
89 views

Optimizing a diagonal matrix-vector multiplication (?diamv) kernel

For an (completely optional) assignment for an introductory course to programming with C++, I am trying to implement a diagonal matrix-vector multiplication (?diamv)...
2
votes
0answers
40 views

Converting list of sequences into one-hot vectors

I have an array of dim 1000 x 150 where I have 1000 strings each of length 150. And the strings only contain ATCGN (these are ...
3
votes
0answers
86 views

Was this an idiomatic and prudent way to extend R's matrix multiplication syntax? Should I have used R's object system?

After reading one too many Lisp books, I decided to try extending R's syntax. My goal was to implement repeated matrix multiplication in a way such that I could write ...
3
votes
2answers
172 views

Array To Matrix

I made a method that takes an array and converts it to a matrix, given that it is a valid conversion. However, there is some redundant code in the beginning and I thought maybe you could help me? I ...
0
votes
0answers
107 views

Vectorized numpy co-occurrence matrix generation

Update The implementation did not consider multiple occurrences of a same word, and self word occurrences. For instance when stride=2 and the word at the position is ...
3
votes
3answers
94 views

Optimizing matrix multiplication algorithm

I have implemented my own version of algorithm to multiply two matrices together and I need someone who know what they are doing to see if there is anything that can be done in a more optimal way. I ...
5
votes
1answer
169 views

2D Matrix in C++20 and Strassen's algorithm

I wrote C++20 implementation of a simple matrix class and its usage in Strassen's \$O(n^{lg_2{7}})\$ matrix multiplication algorithm. Live demo: https://wandbox.org/permlink/JaSC8fQccFbcl1QY (For n = ...
5
votes
1answer
111 views

Optimizing Matrix class with less calls to new

I'm designing a Matrix class and I feel like what I've come up with requires too many calls to new. I know it's possible that caring about this is premature, but I ...
5
votes
2answers
735 views

Multithreaded Matrix Multiplication in C++, improving efficiency?

Here is a very simple Matrix Multiplication console application using multiple threads (one per row), I'm just looking for feedback to keep improving :) thank you in advance ...
2
votes
3answers
105 views

How can I optimize my Von Neumann neighborhood algorithm?

I am working on a small project that requires finding Von Neumann neighborhoods in a matrix. Basically, whenever there is a positive value in the array, I want to get the neighborhood for that value. ...
1
vote
1answer
83 views

Simple C++ Dynamicly allocated Matrix with only one memory allocation [closed]

I was bothered with existing matrix allocation methods that take variable rows and columns, so I made a small class that only needs one memory allocation. ...
8
votes
1answer
129 views

Computing sums of weird pattern in 2D array as efficiently as possible

This is a problem from Hackerrank (https://www.hackerrank.com/challenges/2d-array/problem). We're given a 6x6 (always) 2D array and asked to compute the sums of all the hourglass patterns in the array....
2
votes
1answer
67 views

Improving performance of function to multiply vector with a matrix?

I wrote this function to multiply vector with a matrix and I was wondering if someone experienced can spot something can improved its performance. ...
0
votes
2answers
78 views

Better way to write this program in java?

I am new to writing java code and I would like to improve my skills. I would like someone to review and critic me on where I can improve on. Here is a small program I wrote in java about matrices and ...
2
votes
1answer
77 views

Procedural generation of a general matrix representing a tile map

The problem is to design an structure which generates "uniformly" the next one in an initially zero matrix. Taking an arbitrary index i in the range [0,m-...
4
votes
1answer
110 views

Basic Integer Matrix Implementation

I need to write a CustomBasicMatrix class implementation for college. This includes basic operations such as int and ...
2
votes
0answers
68 views

Cosine Similarity Matrix Loss Function

I am currently implementing this paper on generalised end to end loss: https://arxiv.org/pdf/1710.10467.pdf A batch of N speakers and M utterances are fed to the model which outputs an embedding ...
5
votes
1answer
71 views

Matrix template with a vector buffer

I need some feedback, please. Goals to practice: templates, std, interfaces, return value, constructors and some idioms. People often suggest to use a library, but it's not the goal of this exercise, ...
5
votes
1answer
72 views

Closest Pair heuristics, graph with adjacency matrix in C++17

I was trying to solve a problem that was briefly mentioned at the beginning of the "The Algorithm Design Manual" by Steven Skiena (Ch 1, Problem 26). It took me some time to build a working ...

1
2 3 4 5
13