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.

learn more… | top users | synonyms

2
votes
0answers
33 views

Where is the bottleneck in my Cython code?

The profile tells me it took ~15s to run, but without telling me more. ...
4
votes
0answers
47 views

Refactoring while-do array comparison function into tail recursion with F#

As part 2 of my other question concerning this long running project I've been inquiring about on CR, I reimplemented my generic function for determining if an array of arrays is a sub-array or ...
6
votes
3answers
204 views

Inner product of random floats written to file

My goals are to make this code: faster more idiomatic C++ What the code does: take an integer command-line argument N make a vector of ...
4
votes
5answers
188 views

Search algorithm for specific values in a 3D array/matrix being super slow

I'm trying to create code that reads a text file (containing (double) numbers between 0 and 1) and filling up a 3D array/matrix (calling it matrix from now on) with ...
9
votes
3answers
374 views

How many semi magic squares are there?

I want to write a program to work out how many semi-magic squares there are. Here is the definition of semi-magic squares If we define \$H_n(t)\$ is the number of semi magic squares which ...
6
votes
3answers
79 views

Searching all diagonals of a 2D M x M array

I've started writing a piece of code to help me search for an object in all the objects found in the diagonals of an M x M 2D array. Though the code works, I'd like to know if there is a way I can ...
3
votes
1answer
41 views

Initializing an array of relative coordinates of all adjacent 2D matrix cells

The program should output this: _1 _1 _1 0 _1 1 0 _1 0 1 1 _1 1 0 1 1 Currently I have this code: ...
11
votes
4answers
1k views

“Two-pass algorithm” implementation in Java

I'm rather new to Java and to algorithms in general. I implemented the so called Two-pass algorithm, and want to know if there are improvements to my way of implementing it. What it does is it takes a ...
6
votes
1answer
79 views

Linear algebra, reduced row echelon form - function 1

This is a derivative post from here. This is just a general review, so the question is the same: Is there something... That you would consider as a bad practice and why? That is just bad in some ...
5
votes
1answer
95 views

Linear algebra, reduced row echelon form

The code that I am sharing here for you to review today, is a segment of a JavaScript library that I am going to write as time goes by for fun. It is only the two functions in the following code: ...
1
vote
0answers
25 views

Avoiding boundaries if-cases when filtering image matrix

I have the following MATLAB Code which I want to optimize. It's related to an image matrix (2D) which I want to filter. Though it is MATLAB code, the same problem would arise in C code. The problem ...
1
vote
0answers
32 views

Why does lu-factorization make my program slower?

I'm trying to calculate the smallest eigenvalue of the matrix A by using the "inverted exponentiation method" (see the code). I manage to find the smallest eigenvalue, but when I try to optimize the ...
3
votes
1answer
79 views

Point in a polygon algorithm

I am implementing a Point in polygon algorithm. Inputs: M, N: size of the matrix poly: a ...
2
votes
1answer
58 views

How can I enhance my jigsaw puzzle solver function?

I'm working on writing code which gets several pieces of an image, and reconstructs them to one whole picture. The images are represented by matrices, and two pieces should be "glued" if the right ...
5
votes
1answer
113 views

Optimizing multiplication of square matrices for full CPU utilization

Cross-post from Stack Overflow since this is very code intensive Problem I am learning about HPC and code optimization. I attempt to replicate the results in Goto's seminal matrix multiplication ...
2
votes
1answer
42 views

Finding given element in minimum steps from matrix [closed]

A N*N size matrix is entered. The condition is that each element of the matrix is greater than the elements above it and left to it. Or, it can be said that all the elements on the right side and ...
5
votes
2answers
160 views

Calculate fibonacci in O(log n)

This program calculates the \$n\$th fibonacci number, in \$O(\log n)\$ time. I'm looking for code review, optimizations, and best practices. ...
2
votes
1answer
29 views

Tridiagonal Lists in Scheme

...
3
votes
0answers
50 views

my arcBall rotation code

I am trying to visualize a pointcloud centered around the origin. I also want to have a user controlled rotation for which I found the arcball. Below is my implementation. ...
4
votes
1answer
63 views

Optimization of matrix determinant calculation

I have this algorithm that calculates the matrix determinant using recursive divide-and conquer-approach: ...
2
votes
1answer
40 views

Less For, more MATLABesque?

I have written a piece of MATLAB code that (hopefully) calculates CECT. I have two matrices of psychophysiological measures - one for brain data, one for heart rate; both are of the format epochs * ...
10
votes
3answers
395 views

Find biggest basin

Problem Statement A group of farmers has some elevation data, and we’re going to help them understand how rainfall flows over their farmland. We’ll represent the land as a ...
10
votes
2answers
441 views

Finding average of eight immediate neighbors of a matrix

I have this basic Java code to find average of eight immediate neighbors of a matrix. Is there any way to simplify or merge any part of it, or can I refactor it? I'm a beginner in Java programming ...
10
votes
1answer
569 views

Matrix multiplication

Below is the code that I've written for matrix multiplication: ...
3
votes
1answer
65 views

Sort 3x3 grid by rotating 2x2 subgrids

This question originates from this post. Anyway, I'm trying to solve the following problem: Given a 3x3 grid with numbers 1-9, for example: 2 8 3 1 4 5 7 9 6 I ...
3
votes
2answers
45 views

Implementing Transpose

I'm implementing transpose in Haskell. -- transpose [[1,2,3],[4,5,6],[7,8,9]] -- [[1,4,7],[2,5,8],[3,6,9]] Please give it a ...
6
votes
2answers
60 views

Increment the neighbors of a cell in a matrix

Let's say you want to increment the cells around the position (x,y) in a square matrix m of size ...
4
votes
1answer
60 views

Matrix rotation efficiency

I am not sure if I should be using recursion or not or if it even helps in increasing the performance of my algorithm. I feel as though I am creating and replacing too many arrays by calling my inner ...
4
votes
1answer
60 views

Performing a special multiplication on two square matrices

I have a function called mult2 that takes in two square NumPy matrices and returns a matrix that is the result of a special multiplication: ...
6
votes
1answer
57 views

Average of positive and negative part of numpy matrix

I’ve got a matrix of data and I want to take the average of the positive and negative parts of the values. Is there a more Pythonic way of doing it? ...
6
votes
1answer
94 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. ...
4
votes
1answer
110 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 ...
2
votes
1answer
117 views

Parsing MWNumericArray to C# code optimization

This is my function returning matrices from Matlab. This code run very slowly. I was trying to use Parallel.For in-order to run it in parallel threads but I got ...
5
votes
1answer
134 views

Searching in a sorted 2D matrix

If I was at an interview, and wrote this code, what would you think? Please be brutal. Time it took to wrote it: 13 minutes Problem: Write an efficient algorithm that searches for a value in an ...
7
votes
2answers
786 views

Repetitive For Loops in 2048 Game

I have the following function defined in a program that implements the 2048 game. I tried condensing the repeating part of the code into one loop containing +1 offset variables for the indices, which ...
13
votes
1answer
159 views

Finding a zero crossing in a matrix

I am trying create an algorithm for finding the zero crossing (check that the signs of all the entries around the entry of interest are not the same) in a two dimensional matrix, as part of ...
3
votes
1answer
112 views

Shift data in multidimensional array

I'm currently facing a problem where I have to shift data in a multidimensional JS array in different directions, but I think the first solution I whipped up is not as efficient as it could be (some ...
9
votes
1answer
86 views

Gauss-Seidal implementation

The code is an implementation of the Gauss–Seidel method. I would like a general review of the code. PS: I use code::blocks IDE ...
2
votes
2answers
148 views

A matrix with square diagonals and transpose being increments of other

Construct a matrix with the following property: North-west to South East diagonals are squares. Matrix[i][j] + 1 = Matrix[j][i] for each i less than j. Example of such m a matrix is ...
5
votes
1answer
87 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 ...
2
votes
1answer
624 views

Turning 1D array to 2D array in TicTacToe

To check a win in my TicTacToe game, I have created a 2D array that contains all the combination that a game can be won in, like so: ...
29
votes
0answers
408 views

Capture the notion of invertible functions

I find sometimes it is useful to capture the notion of invertible functions. The idea is that if two functions f :: a -> b and ...
7
votes
2answers
236 views

Counting linear conflicts of the state of 8 puzzle for heuristic

I need to find linear conflicts of 8 puzzle state, state is represented by int[9], goal state is {1,2,3,4,5,6,7,8,0}. A linear conflict would be if in a line two ...
9
votes
2answers
310 views

C struct or pointer to struct?

I am currently using this code (and more) to deal with 2D matrices. I am not very proficient in C, so I am not quite sure, if this is a good way of doing it. I've seen other people in similar ...
5
votes
3answers
81 views

More efficient (or correct) way to make image grouping work?

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 ...
11
votes
5answers
565 views

Set matrix zeros

I solved this problem in about 11 minutes (with all 50+ test cases passed). I think most of you already know me by now, and I truly appreciate your advice, but please be brutal and judge me as if I ...
5
votes
2answers
294 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? ...
1
vote
2answers
193 views

Performance with C++ algorithm

This is an algorithm I'm trying to optimize. I was trying to use openMP without any success. I know the code is long but most of it is params init. Please try to explain why I need to change any ...
5
votes
1answer
57 views

Orchard Partitioning in to close-to-equal sectors

The task (from this site) is to create a program that will solve a problem where a matrix (size n * n), which contains integers, is to be divided into four parts, the sums of which are as close to ...
10
votes
3answers
460 views

Row/Column Transpose

I was wondering if there is a smarter way of doing the following code. Basically what is does is that it opens a data file with a lot of rows and columns. The columns are then sorted so each column is ...