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
67 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 ...
11
votes
3answers
14k 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 ...
1
vote
1answer
1k views

Test whether or not a 4x4 matrix is a magic square

Here is what I have. I have it outputting most of the sums just so I can check there values. I think the problem is with the value of the elements in the array storing the column sums. I would greatly ...
3
votes
2answers
159 views

Path from source to destination, with increasing values

Given a source and destination, in an integer matrix, find path, such that the next position in the path has a greater than or equal to value than the previous position. In other words ...
4
votes
2answers
265 views

Returning all the LIS of given array of int

I have this assignment where I'm supposed to code an algorithm for finding the quantity of Longest Increasing Subsequences from an array of (different) integers and print them all. I developed one ...
14
votes
2answers
7k views

Count the one islands in the matrix

What is an island? A group of connected 1s forms an island. For example, the below matrix contains 5 islands: ...
2
votes
0answers
117 views

Increasing speed of parity check matrix

The code runs fine and takes 100s to complete it for 5 iteration. I need to reduce it to take less time with the same number of iterations. h = 324 by 648 matrix The code is that of FFT Belief ...
-1
votes
2answers
614 views

Matrix multiplication of arbitrary sizes [closed]

This function is for multiplying two matrices together. It's kind of messed up because the result is actually supposed to overwrite the object that called it, or since it's ...
6
votes
2answers
43k views

Given N*N matrix, rotate it by 90 degree to left and right without extra memory

I'm looking for a code review, clever optimizations, and good coding practices. Unit testing has been a visual inspection and concluded expectations match. Also, is the space complexity of the extra ...
3
votes
2answers
3k views

Searching a 2D matrix for a consecutive sequence

I've been solving problems on checkio (and trying to digest other's code) in order to improve my Python. My main goals are to learn to write more idiomatic Python and to explore the language more ...
5
votes
2answers
189 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 ...
1
vote
1answer
1k views

MaxSum sub matrix within a matrix

Code review for best practices, optimizations, code cleanup etc. Also requesting verification of the complexity: O(row*row*col). ...
5
votes
2answers
12k views

Rotate an image by 90 degrees

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

Find mirror image of a matrix

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

Defensive programming type-checking

I have issues with dynamically typed languages, and I tend to worry about type a lot. Numpy has different behaviour depending on if something is a matrix or a plain ndarray, or a list. I didn't ...
2
votes
1answer
2k views

Project Euler #82 - path sum: three ways

Project Euler problem 82 asks: Here's my solution: ...
3
votes
1answer
8k views

Clockwise and counterclockwise spiral matrix traversal

An interviewer asked me to write clean Java code for clockwise and counterclockwise spiral matrix traversal. e.g. {{1,2,3}, {7,8,9}} becomes ...
2
votes
1answer
613 views

Matrix of checkboxes - only 1 allowed in a row

Task Create a matrix of checkboxes. The user must be able to select only 1 checkbox in a row or unselect all of them. Solution ...
1
vote
1answer
612 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 ...
2
votes
1answer
276 views

Reading Multidimensional arrays [closed]

I am building a cypher program which uses a matrix of numbers and letters. A message is encoded according to the row and column each letter of the message is found in the matrix. I am trying to find ...
3
votes
1answer
447 views

Simplifying loop for Incidence Matrix

I had to work in the Transport Problem and we're asked to try to make the fastest code for big matrices, so we're advised to try to avoid loops. And the only one I've got and I cannot imagine how to ...
2
votes
1answer
3k views

Java: Sudoku solver

I'd like a review on anything including optimizations, corrections, suggestions for robustness, adherence to good coding practices, etc. I also request verification of the complexity: O(nn), where n ...
4
votes
2answers
3k views

Prolog Sudoku solver taking too long

I was wondering if there's any way I can improve this code's execution. I want to use it on a 9*9 grid, but it takes too long to solve this as 4*4. This program takes as input a 4*4 matrix ...
2
votes
1answer
154 views

Given set of cubes can we get a given word?

Given some cubes, can cubes be arranged such that an input word can be formed from the top view of the cubes? For example: assume an imaginary cube with only 3 surfaces where ...
1
vote
4answers
230 views

How can I make this code more readable and efficient?

How can I rewrite this code to make it more readable and, if possible, more efficient? The conditions are entirely necessary in this problem, but how could I rewrite those ...
4
votes
2answers
2k views

Optimize Scipy Sparse Matrix Factorization code for SGD

I'm working on implementing the stochastic gradient descent algorithm for recommender systems (see Funk) using sparse matrices with Scipy. This is how a first basic implementation looks like: ...
2
votes
1answer
431 views

Minesweeper, Bombcount method

I have a method which checks all of its surrounding squares and returns the number of bombs around it. It uses a long list of if statements, which is pretty ugly ...
2
votes
1answer
163 views

Optimizing this matrix shifter

I need to optimize this piece of code I made because this will run in real-time mode. It's a matrix shifter that pulls downward and will neglect any transparent element. Code: ...
2
votes
2answers
12k views

Finding a route in maze matrix

Maze puzzle A 1 in input matrix means "allowed"; 0 means "blocked". Given such a matrix, find the route from the 1st quadrant to the last (n-1, n-1). I would like to get some feedback to ...
3
votes
3answers
7k views

Neighbors of a matrix element

I would like a code review to make this code better, clear, and concise. The problem it's solving is as follows: Given a matrix, print the circumference of each of the items. For example: ...
1
vote
3answers
1k views

Matrix transposition of a string

Per a Reddit Daily Programming Challenge, I am performing a matrix transposition on a string using JavaScript. Example input: 'The quick brown fox jumped over the lazy dog' Output: ...
2
votes
1answer
1k views

Matrix transpose function

I have a matrix transpose function that takes arrays with a possibly different number of rows and columns. How can I improve performance and code quality? ...
11
votes
1answer
474 views

10x10 bitmapped square with bits

This program prints out a 10x10 square and uses only bit operations. It works well, but I don't like that global array. Can you tell me if the code is proper or not? ...
2
votes
1answer
669 views

Thread-safety of Matrix class

Please criticize the MatrixNotThreadSafe class and other classes. How can I improve the design of the Matrix interface? How can I make the classes and tests clearer?...
4
votes
2answers
170 views

Long expression to sum data in a multi-dimensional model

I am porting a linear optimization model for power plants from GAMS to Pyomo. Models in both frameworks are a collection of sets (both elementary or tuple sets), parameters (fixed values, defined over ...
2
votes
1answer
6k views

Program to display a matrix in a spiral form

I found an interview question which requires us to print the elements of the matrix in a spiral order starting from the top left. I need some pointers on how to improve my code: ...
3
votes
3answers
354 views

Simple matrix class - version 2

As suggested on my previous question, I am posting my revised code for feedback. One thing that caught my attention is that my program actually runs slower after adding the modifications. It was ...
2
votes
3answers
4k views

Matrix and Vector4 classes

I am working on a project that needs algebra operations. I have coded a Matrix class (only needed 4x4 matrix), and a Vector4 ...
3
votes
4answers
11k views

Simple matrix class

I have built a 3D matrix class in C++, mainly for data I/O, for a project I am working on. The code works ok, but I would like you to help me improve it. Are there any bad programming practices I am ...
1
vote
1answer
1k views

Is my 4x4 matrix multiplication on a 1D float array correct?

I'm trying to develop my own math library to use on a Voxel engine, but I'm worried about Matrices multiplication. Everywhere I saw people using 4x4 Matrices on a 2D Float Array but I'm using a 1D ...
2
votes
2answers
344 views

Utilizing std::map and std::array for displaying a modulus grid

I've written a modulus-type program (using std::vector). The user inputs a number, and the program displays a modulus grid pertaining to that number. This is what ...
2
votes
1answer
4k views

Determinant of a binary matrix

I'm looking for the best and fastest way to do a determinant, for determinants until 15x15. ...
4
votes
2answers
5k views

Calculating n x n determinant

According to instructions and sample code from MSDN Magazine and comments from post here determinant of n x n... I changed code to be like this: ...
4
votes
3answers
171 views

Manipulating matrices for 3D drawing

I've written a short library for manipulating matrices for 3D drawing. I've tried to strike a balance between speed and readability. Anything to improve? ...
3
votes
2answers
651 views

Pair programming matrix

At work, we have a "pair programming ladder" where you can keep track of who is pairing with whom (based on check-ins). The idea is to promote "promiscuous pairing" where each developer eventually ...
2
votes
1answer
545 views

Determinant calculation of a matrix of any degree

My program calculates the determinant of a matrix of any degree. If you really can't understand my comments or indentifiers please let me know. ...
3
votes
1answer
3k views

Build a combinatorial matrix from two vectors

I want to define a matrix of values with a very simple pattern. I've achieved it with the code below but it's ugly - very difficult to read (I find) and surely not as optimal, in terms of performance, ...
1
vote
1answer
3k views

Generating adjacency matrix on random cout of graphs with output the matrix

I've developed program, which may work with graphs and its edges (connections between vertices): http://ideone.com/FDCtT0 ...
2
votes
1answer
2k views

Sparse matrix multiplication

I am working on a sparse matrix application in C and I choose compressed sparse row (CSC) and compressed sparse column (CSC) as my data structure for it. But the difficult part is I cannot improve my ...
1
vote
3answers
5k views

Searching for an element in a 2D array

For example, given a 2D array (a matrix): {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} What are the solutions to find a number, such as 6? Here's the code I ...

1
8 9 10
11
12