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
1
vote
0answers
8 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
77 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 ...
6
votes
1answer
102 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
108 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
155 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
95 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
80 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
94 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
57 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
76 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
72 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
98 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
42 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
68 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
64 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 ...
4
votes
0answers
63 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
71 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
155 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
125 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
64 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
70 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
29 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
58 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
94 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
47 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
27 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
24 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
50 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
55 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
55 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
44 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
22 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
37 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
137 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
404 views

Matrix Exponentiation in Python

I recently wrote a python code for matrix exponentiation. Here's the code: ...
6
votes
2answers
65 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
508 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
44 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
136 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
271 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
220 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
346 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
139 views

Rotate square matrix clockwise by 90degrees

...
3
votes
1answer
136 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
51 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
326 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
90 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
283 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
102 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 ...

1
2 3 4 5
13