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
6
votes
1answer
235 views

The Last Lost Bubble Shooter - a Board game for children

In this game the pieces are trains and you move forward on the track (never backwards) in search of your goal. The players move based on a combination of resources (Soap and Water to make Bubbles) ...
6
votes
1answer
499 views

Householder transformation

I'm trying to make this Householder method run as quickly as possible. It runs fine now, but I'm still a bit new to java, is there anything you guys see to make this run faster? ...
6
votes
2answers
263 views

Quaternion rotations and preparing matrices for a shader

I am implementing an OpenGL ES 2.0 renderer in c. I want to use quaternions for rotations. Please take a look at the way I am implementing the rotation math. Everything looks as expected when the ...
6
votes
1answer
2k views

Calculating Euclidean norm for each vector in a sparse matrix

Below is a naive algorithm to find nearest neighbours for a point in some n-dimensional space. ...
6
votes
1answer
3k views

Gaussian Elimination with Pivots

I'm pretty new to python, and coding in general. For practice, I've written the following code, which uses Gaussian reduction to solve a system of linear equations. ...
6
votes
1answer
606 views

Leetcode 54: Spiral Matrix

Problem statement Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order. For example, Given the following matrix: [   [ 1, 2, 3 ], ...
6
votes
2answers
9k views

Rotate Matrix using Python

This is my solution to Exercise 1.7 from Cracking the Coding Interview. I would appreciate any feedback on coding style and algorithm efficiency. I do know that there is an existing function in ...
6
votes
1answer
551 views

3D matrix rotation in homogeneous coordinate space

Assuming that the framework is in place to handle the difference between row and column major matrices, I am curious to know if in a header based library such implementation is semantically and ...
6
votes
1answer
2k views

Implementing the CutHill-McKee Algorithm

I am very much interested in the Reverse Cuthil McKee Algorithm. I have seen Fortran and C or C++ implementations of it, and I decided that it would be a nice exercise to implement it in Python. I ...
6
votes
1answer
165 views

Multivariate normal density using Woodbury matrix inversion lemma

I'm trying to speed up by multivariate normal density function by taking advantage of the fact that the covariance matrix is of the form A + U C U'. The inverse of such a matrix can be calculated ...
6
votes
1answer
2k views

Extending numpy array by replacing each element with a matrix

Suppose I have a H*W numpy array like this (H=3 and W=2): ...
6
votes
1answer
261 views

Encryption/decryption by matrix multiplication in C

I need to encrypt and decrypt text, image and video with a program in C with a matrix. My program is working but it's really slow, how can I improve its speed ? specially for the decrypt part. Each ...
6
votes
1answer
1k views

Sparse matrix compressed sparse row (CSR) in Python 2.7

Brief introduction for CSR: The compressed sparse row (CSR) or compressed row storage (CRS) format represents a matrix M by three (one-dimensional) arrays, that respectively contain nonzero ...
6
votes
0answers
58 views

Reading sparse matrix from binary file

I have binary files containing sparse matrices. Their format is: number of rows int length of a row int column index int value float Reading ...
6
votes
0answers
75 views

Perl gradient noise generator

I'm working on 2-D top-down graphics engine, and need a way to simulate clouds. My idea was that I could create a layer comprised of a matrix of rectangles whose alpha value would be picked from a ...
5
votes
3answers
1k views

Transposing a 2D array

Would you have any suggestions for improvements for the code below? ...
5
votes
3answers
132 views

Image-grouping using bit matrices

It might be easier to read the explanation of what I was trying to do, and implement it a completely different way, rather than go through the code. But the code does what I want it to do, just ...
5
votes
2answers
8k views

Am I multiplying two matrices together correctly?

I just wanted to know if I'm doing this right. Note that all the matrices are int[16]s. ...
5
votes
5answers
281 views

Create matrices of a certain format

I need to create matrices that follow a specific format: the matrix is a square NxN matrix and the off-diagonals all have the same value (param) and the diagonals ...
5
votes
3answers
1k views

Are there any memory issues with this Eigen QR wrapper?

I am writing a wrapper to Eigen QR for my personal use and I am wondering if there are any memory leaks or undocumented behavior in my implementation, especially in the function ...
5
votes
2answers
11k views

Rotate an image by 90 degrees

Looking for review, good practices, optimizations, clean code tips etc. ...
5
votes
2answers
2k views

Fixed size matrix implementation

I implemented a fixed-size matrix class which supports basic matrix operations (cannot use C++11). What do you think, and how could it be improved? ...
5
votes
5answers
2k views

Finding the maximum row of a 4x4 matrix

I have written a recursive function that I believe will return the 'maximum' row of the 4x4 matrix it is fed. By 'maximum' I mean that the maximum row of the matrix. ...
5
votes
3answers
2k views

Matrix Implementation using struct in C

Follow up on this post. I have refactored my code and created a matrix_t struct and implemented various functions to create, delete, modify and perform arithmetic on them. ...
5
votes
2answers
120 views

Simple matrix library in C++

Today I started learning C++ and at the end of the day have made a simple generic matrix class. I'm looking for feedback on techniques and features. It's still not complete, though. But everything ...
5
votes
2answers
344 views

Printing an N*N array in the rectangular/circular/spiral fashion

The problem is to print an N*N array and fill it with numbers(starting from 1 at (0,0)) in the rectangular/circular/spiral fashion, going inwards, ending at the N*N value. Also find and count the ...
5
votes
1answer
268 views

Immutable Matrix

I'm writing implementations of some numerical methods to solve linear equations systems, those implementations use the following Matrix class. I'm trying to get this class immutable, due to that the ...
5
votes
1answer
470 views

Dynamic matrix in web browser

Today, my project was to make a matrix in my web browser. It is really slow, so help with optimizing it would be nice. It runs slow on my PC, yet alone my iPod 4 which this is going to be for. ...
5
votes
1answer
1k views

Path sum - Dijkstra's algorithm in F#

I'm learning F# and I've decided to solve Project Euler's Problem #81 with Dijkstra's algorithm. In the 5 by 5 matrix below, the minimal path sum from the top left to the bottom right, by only ...
5
votes
3answers
154 views

Finding black cluster size distribution for square grid at different probabilities of black elements (averaged over a certain number of iterations)

Context: I had asked a related question on Stack Overflow. On receiving several helpful hints from the commentators there, I could successfully implement averaging of the size distribution over a ...
5
votes
2answers
91 views

Extract the largest value for each day from a matrix

I have a matrix in which the right-most elements are repeated YYYYMMDD dates in descending order, for example: ...
5
votes
1answer
130 views

Calculating diagonal difference

I was trying to solve a problem concerning the difference of the diagonal sums of a matrix (using C99): ...
5
votes
2answers
1k views

Spiral Scanning for matrix using recursion

I have written code for scanning an N x M matrix in spiral order using a recursive function. It uses 5 parameters - including 2 extra variables: call to keep ...
5
votes
1answer
4k views

Optimize vector rotation

I have a trivial function that rotates 2d vectors, and a method in a class representing a polygon that rotates every point in the polygon around an origin. The code is fairly optimized as it is, but I ...
5
votes
1answer
74 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 ...
5
votes
1answer
49 views

Multiplying a Matrix with its Transpose

Currently, I am in the process of optimizing a MIPS assembly program that takes a n x n matrix and multiplies it with its transpose. I am trying to optimize my matrix calculation algorithm so that it ...
5
votes
1answer
77 views

Manually writing a function matrixpower() in R

Problem 1 - Matrix powers in R R does not have a built-in command for taking matrix powers. Write a function matrixpower() with two arguments mat and k ...
5
votes
1answer
207 views

Determinant of a matrix of doubles

I have been working with some matrix functions and need the determinant. I have looked at several examples, but they all seem to use a hard coded size for the matrix, or calculate for a matrix of int, ...
5
votes
1answer
116 views

Mean of the squares of differences for a large matrix

I have tried to obtain speed gains by transferring Matlab calculations to C and call it using .mex. My goal is to operate on a matrix \$B\$ which has roughly the dimension 10000x1000 $$ \frac{1}{\...
5
votes
1answer
474 views

In 8-puzzle finding nr of steps moving a tile to the right place

In 8-puzzle I want to count the number of moves it would take to move a specific tile to it's goal place. The problem is my method for this is >100 lines long which is obviously way too much. I'll ...
5
votes
1answer
190 views

C++ Dataset class

C++ newbie trying to build a class to represent a dataset for the purposes of building predictive models of the form y ~ x0, x1,... Since this is version 1, I'm assuming some nice properties about my ...
5
votes
1answer
82 views

Blurring a given image using moving average in Python 3

I've tried solving the following HackerRank question: Write a function blur_image() that takes as a parameter an image in the form of a nested list ...
5
votes
1answer
911 views

Determinant using Gauss Elimination

We had a question in examination to compute determinant of general square matrix. Now I had made the normal program using Laplace Formula of determinant, ie, recursive solution. Now I was thinking of ...
5
votes
1answer
383 views

Matrix implementation with Rank and Inverse calculation using Gaussian Elimination in Java

Disclaimer Some things that I must state: This is just for practice. I want to know the various algorithms in linear algebra in detail. I will not use this in a practical scenario. Except for ...
5
votes
1answer
355 views

C++ Template Matrix Class - WIP

I've created simple matrix class in c++ and I would like to know what you think about the code. I've left the implementation in header file for simplicity for now. The class is not finished yet, it ...
5
votes
1answer
85 views

Calculating how similar two objects are according to a database

I want to calculate how similar two objects are according to a database. However the code is very slow; it takes around 2 minutes to analyze just 3 objects. How can I speed it up? I have tried to ...
5
votes
1answer
2k views

Java method to make a string representation of a matrix

I have coded this static method for converting a double matrix into a nifty String. It considers the width of the matrix to be ...
5
votes
1answer
218 views

Creating a special Toeplitz matrix in R

I'd like to know if there is a standard way of creating a matrix like the one shown below using the R programming language. $$ \begin{bmatrix} 1 & \rho & \rho^2 & \cdots &...
5
votes
2answers
186 views

Optimizing garbage collection for local objects

I am trying to make a 3D application with OpenGL/LWJGL at the moment, but I am now already hitting some limits on the JVM, most likely due to a configuration that needs to be done. I have the ...
5
votes
2answers
2k views

Finding the largest product of four consecutive numbers in a grid

Project Euler #11 asks to find the largest product of four numbers of a grid, where the four numbers occur consecutive to each other vertically, horizontally, or diagonally. Here is my solution in ...