# 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.

597 questions
Filter by
Sorted by
Tagged with
57 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 ...
25 views

### SPOJ MIXTURES - Mixtures [closed]

I am trying to create recursion based solution for Mixtures and i am getting correct ans for every possible test case i can figure out but get Wrong answer on spoj, what i am missing ? NOTE: I know i'...
57 views

53 views

### Rotating a matrix by 90 degrees

I'm going through books and various questions to improve my algorithm knowledge. I solved each NxN matrix first by hand and applied that process to build the code from that. I have done my best to ...
48 views

### Improving Performance of Numba For-Loop and Matrix Multiplication for Time Integration Solver

I am writing some code that performs a simple time-history integration solver (Newmark method for structural dynamics) and I looking for some suggestions in how I can improve the performance of my ...
32 views

### Givens QR decomposition in R or C++: poor performance (or lack thereof) for rectangular matrices

My own Givens-based QR decomposition function in R (pseudocode from Politecnico of Turin's math department) is the following: ...
25 views

### Efficiently update matrix calculations in Python

I'm trying to create functions in Python that would update calculations for a matrix only for new entries. These functions are created within a Design class, where users would submit a design into an ...
19 views

### JDS - Cuda implementation

I am trying to implement the Jagged Diagonal Storage code in Cuda for Sparse Matrix - Vector multiplication. The code I wrote is as follows but I'm not sure about it: ...
74 views

Code Problem ...
44 views

### Converting a natural number to a permutation matrix in Python. How to speed it up perhaps avoiding messing around with lists, sets and dicts?

It is something a bit complex to explain here, but the code bellow takes a 128-bit number and converts it into a permutation matrix, a beast which I have already faced before. The matrix is ...
53 views

### How to efficiently (fast) calculate the transpose of a *permutation matrix* in Python3?

The permutation matrix is represented as a list of positive integers, plus zero. The number indicates the position of the 1 in that row, e.g. a number zero would mean that the 1 is in the right-most ...
54 views

### Matrix problem, the path that is the flattest

So in this problem I am given an NxN matrix, in which each value of the matrix represents an altitude. I need to find the best path from the top-left corner to the bottom-right one, my moves being ...
32 views

### Implementing basic graph theory functions in APL with matrices

I had to solve three problems on graph theory that I solved by implementing a utility function and 3 functions, one for each of the problems. The problem set defines the input for all my functions as ...
66 views

### Extract numerics from matrix A with logical matrix B

I have a matrix A containing numeric values and a matrix B containing 0/1s: ...
1k views

### numpy performance of norm calculation using variable dimension

I am looking for advice to see if the following code performance could be further improved. This is and example using a 4x3 numpy 2d array: ...
19 views

### How to optimize code to take advantage of NumPy broadcasting when calculating pairwise correlation?

I'm trying to take advantage of NumPy broadcasting and backend array computations to significantly speed up this function. Unfortunately, it doesn't scale so well so I'm hoping to greatly improve the ...
24 views

### LeetCode: Search a 2D Matrix C#

https://leetcode.com/problems/search-a-2d-matrix/ Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row ...
619 views

### Computing tangent space basis vectors for an arbitrary mesh

This is more like a share and a request than a question. I converted Eric Lengyel's code, which calculates tangents of a mesh for the purpose of texturing and normal mapping, to support SIMD. For this ...
64 views

### Fast execution of function which resembles matrix multiplication

I am trying to make the following function as fast as possible on large matrices. The matrices can have dimensions in the range of 10K-100K. The matrix values are always between 0 and 1. The function ...
63 views

### Striping a matrix concentrically, anticlockwise

Given a matrix you shall stripe the matrix, such that every number that has equal distance to the matrix border will be filled into an array. For examples see code comments. ...
531 views

### HackerRank NCR codesprint: Spiral Message

Problem statement: https://www.hackerrank.com/contests/ncr-codesprint/challenges/spiral-message You've intercepted an encoded spy message! The message originated as a single line of one or more ...
2k views

### Print concentric rectangular patterns

I am solving interview questions from here. Problem : Print concentric rectangular pattern in a 2d matrix. The outermost rectangle is formed by A, then the next outermost is formed by A-1 and so on....
174 views

### Matrix Exponentiation in Python

I recently wrote a python code for matrix exponentiation. Here's the code: ...
314 views

### Matrix with spiral increasing values

This generates a square matrix with spiral inward increasing values. How can I reduce this code? Input Number = 3 Output 1 2 3 8 9 4 7 6 5 ...
457 views

### Template Matrix Class: implemented some basic functionalities

Basically I have written a matrix class for addition, multiplication and scalar multiplication. I need your review of the class implementation below in terms of efficiency, memory consumption and new ...
48 views

### R solution to max product in matrix for four adjacent numbers (Euler 11)

Background This is solution to Problem 11 on Project Euler that is concerned with finding largest product of four adjacent numbers in the provided grid. Other than solving the problem I was also ...
42 views

### Reduction of time for matrix multiplication of pixels [closed]

This part of my code is taking 30 minutes to multiple 300 RGB and Depth images pixel by pixel. How can I reduce this time? This is just a part of big code but this taking lot of time. ...
90 views

### C++ matrix calculator

I wrote a program that is able to perform calculations with matrices: main.cpp (Just for test purposes) ...
192 views

### Simple implementation of nxn Dense Matrix in Java

So far this is what I have completed. Still working on these two methods boolean isIdentityMatrix(DenseMatrix matrix); boolean isInvertible(DenseMatrix matrix); Suggestions are appreciated. Thanks. ...
228 views

### A Matrix Library in C++;

I have written a Matrix library that contains all the main properties of matrices. It's a relatively long project, I am hoping it is ok to post here since I really want to have it reviewed. The ...
635 views

### Pad a ragged multidimensional array to rectangular shape

For some machine learning purpose, I need to work with sequences with different lengths. To be able to process efficiently those sequences, I need to process them in batches of size ...
196 views

### How to increase the efficiency of DLA algorithm?

The algorithm: Place seed at the center of the canvas. Release a random walker from the edge. Random walker sticks to the neighboring sites of the seed/previous points. Repeat N(particles) times. ...
123 views

### C program that dynamically allocates and fills 2 matrices, verifies if the smaller one is a subset of the other, and checks a condition

Yesterday, I asked this question because I was asked to implement a software that used variably sized matrices with C89's limitation, so I had to practise dynamic pointer-to-pointer allocation. After ...
2k views

### Enter the Matrix

I've semi-often been frustrated at the lack of a proper Matrix data structure in VBA. A multi-dimensional array is obviously the right way to handle it, but there is so much missing... for example, ...
212 views

### Matrix Transpose in Golang

I have write a normal programm "Transpose the matrix" in go. Suppose input are always correct. I also read the article An Efficient Matrix Transpose in CUDA C/C++. So I keen to know how I can use Go-...
116 views

...
105 views

### Matrix class with overloaded operator[]

I have implemented a Matrix class that allocates memory using unique_ptr. How to make it more diverse and optimized in terms of memory usage and efficiency? ...
62 views

### Connect Four – get all diagonal and anti-diagonal rows

I started learning python with the connect four game. Now I'm searching for the best way to get all diagonal and anti-diagonal rows of a matrix. It should work with any 2-dimensional matrix. My code ...
179 views

### Count number of unique adjacent cells in a matrix

I want to write an algorithm to count how many islands are in a given matrix. Consider for example: ...
8k views

### Faster solution for row-wise matrix subtraction

I have 2 matrices. I have to calculate the euclidean distance between every row of matrix A and every row of matrix B. In the first solution I loop over the rows of the two matrices and for each row ...