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
5
votes
1answer
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 ...
0
votes
0answers
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'...
4
votes
0answers
57 views

Naive Solver of Matrix with Periodic Boundary Conditions Feedback

I am creating an \$O(n)\$ solver for an \$Ax = b\$ system where \$A\$ has the form \$ A = \begin{pmatrix} a_1 & b_1 &&&d_{u}\\ c_1 & a_2 & b_2\\& \ddots & \ddots &...
2
votes
1answer
51 views

Positive, Negative or zero in a 2D array python

I'm trying to find a way to know if a number on a matrix is positive, negative or zero. Below is my code, but I'm wondering if there is a more Pythonic way to write that. Any ideas? ...
7
votes
1answer
51 views

Python - A Numeric Matrix Calculator/Processor

it's the second object oriented program i've worked on, more details on https://hyperskill.org/projects/96?goal=391. I've added as much documentation as needed, as a first time, to explain each ...
4
votes
1answer
93 views

Generating unique 2D numpy arrays with 2 adjacent row elements swapped while using BFS in Python

So I have a 12 x 6 2D numpy array for input which consists of 7 possible board objects (characters from 'abcdefg'). From a 2D numpy array I wish to generate all the possible unique 2D arrays, in whose ...
1
vote
1answer
47 views

Recursive Matrix Multiplication Algorithm

Can I improve on this any further. Is there a prettier way of passing the array sizes? ...
1
vote
1answer
52 views

Exercism: Class representation of a matrix in Python

The task is to represent a Matrix as a class and to instantiate it from a string such as "1 2 3 4\n5 6 7 8\n9 8 7 6" The class must provide methods for ...
3
votes
1answer
27 views

Print out symmetric matrix from compactly stored array

I have an array of the form (3x3 case as an example) $$A = [a_{11}, a_{12}, a_{22}, a_{13}, a_{23}, a_{33}] $$ corresponding to the symmetric matrix $$\begin{pmatrix} a_{11} & a_{12} & a_{13}\\...
1
vote
0answers
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 ...
3
votes
0answers
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 ...
2
votes
0answers
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: ...
1
vote
0answers
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 ...
2
votes
0answers
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: ...
3
votes
2answers
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 ...
3
votes
1answer
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 ...
1
vote
1answer
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 ...
3
votes
1answer
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 ...
1
vote
0answers
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 ...
1
vote
0answers
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 ...
5
votes
1answer
134 views

Getting a transpose of a matrix of size of n*n where n=2^m using multithreading

The following is a c++ source code to get a matrix (std::vector<std::vector<T>>) transpose in parallel. The span is \$\Theta(\lg^2(n))\$ while the work ...
2
votes
1answer
175 views

Matrix Exponentiation in Python

I recently wrote a python code for matrix exponentiation. Here's the code: ...
6
votes
2answers
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 ...
5
votes
3answers
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 ...
1
vote
0answers
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. ...
1
vote
1answer
90 views

C++ matrix calculator

I wrote a program that is able to perform calculations with matrices: main.cpp (Just for test purposes) ...
5
votes
2answers
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 ...
3
votes
2answers
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 ...
4
votes
2answers
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. ...
3
votes
1answer
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-...
4
votes
3answers
116 views

Rotate square matrix clockwise by 90degrees

...
3
votes
1answer
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? ...
2
votes
1answer
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 ...
3
votes
4answers
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 ...
3
votes
1answer
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 ...
5
votes
1answer
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: ...
3
votes
1answer
98 views

Finding shortest path in matrix

Given an N x N matrix of positive integers, I need to find the shortest path from the first cell of matrix to the last cell of matrix. I can move exactly x steps from any cell, where x is the value of ...
3
votes
1answer
74 views

Using Python to search a sorted 2D Matrix

Code Problem ...
5
votes
2answers
133 views

General matrix class

I have written a matrix class using python, allowing me to perform a variety of operations on matrices. I'm pretty happy with how it performs, and everything works fine. However, I feel like the way I'...
2
votes
1answer
170 views

My custom implementation of MATLAB's imdilate

I have been assigned to implement the morphological dilation operation without using MATLAB's imdilate, and I came up with the following solution: ...
3
votes
0answers
24 views

How would you convert this code to best take advantage of CSS transform for panning/zooming?

I am using react-flow-chart for a job project, but it doesn't implement zoom, and I would like to take the reigns and try applying it myself. I took a linear ...
5
votes
2answers
116 views

Rotate a matrix, using transposition and reflection

I want to compare two solutions to the following question from Cracking The Coding Interview by Gayle Laakman McDowell : 1.7 Rotate Matrix - Given an image represented by an NxN matrix, where each ...
7
votes
2answers
887 views

Magic Square (Python)

Problem Write a method to return a boolean if an input grid is magic square. A magic square is a \$NxN\$ square grid (where N is the number of cells on each side) filled with distinct positive ...
4
votes
1answer
196 views

overlapping rectangles c#

I had to write code for a competition which calculates sum of the perimeter of three overlapping rectangles in a 2D space. rectangle A and rectangles B and rectangle c is overlapping each other.They ...
12
votes
2answers
872 views

Python algorithm that converts array-like data into MathJax

I frequently use MathJax, and often I need to write matrices. Since writing matrices using MathJax is very tiresome task, I decided to automate it. Code: ...
19
votes
4answers
3k views

Matrix class in C#

I've been learning C# during my free time in the past months; before that, I was mostly writing Java, so the transition hasn't been too hard, but I've never had my code reviewed or read by someone ...
2
votes
0answers
59 views

Compute angular distances between data points in a matrix

I am having a hard time speeding up a function that I use to compute angular distances between data points in a matrix. More precisely, I want to compute $$\sum_{r=1}^n|\pi - \arccos\left(\frac{(X_{i}-...
1
vote
0answers
391 views

Fast matrix transpose

I would like to improve the naive matrix transpose algorithm by using a cache friendly algorithm. So far there are 4 variants. Iterate over the source matrix: ...
1
vote
0answers
68 views

Stochastic gradient descent - backpropagation over mini-batches in one go

I have been working through a tutorial on neural networks. I have then been translating the code to java, to help improve my understanding of what the code is doing. The book mentions a way of ...
3
votes
2answers
91 views

Large matrix with lots of repetitive fields (C++)

I wrote a timetabling program and I have been using a matrix to check for clashes between courses. Index (i, j) in the matrix ...

1
2 3 4 5
12