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

5
votes
2answers
89 views

Simple matrix class C++14

I created a simple 4x4 matrix class (column-major). I would like it to be efficient and to use C++14's full capabilities. Can I improve it? ...
5
votes
2answers
116 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 ...
4
votes
2answers
105 views

If zero found in Matrix. make entire row & column zero

Problem is - If in an MxN matrix, a zero is encountered, the entire row and entire column should be set to zero. Example - 8 4 2 2 3 7 1 0 1 9 8 4 ...
6
votes
1answer
55 views

Python matrix implementation

I created a simple matrix implementation and would like some critique of it, for example: Things I could add to make it more useful Ways I could make it more efficient (for example __pow__ or ref()) ...
4
votes
1answer
33 views

Speeding up OpenCL matrix-vector multiplication

So I'd like to get a performance boost above and beyond standard Julia matrix-vector multiply, using my Intel HD Graphics 4000 1536 MB GPU, but I can't do better than an order of magnitude worse ...
0
votes
1answer
42 views

Parse 2D matrix, 2 versions

I'm writing a little C program that computes matrices (for learning purpose). The matrix is fed through arguments in the following form : "{{43,543.324,34},{43,432,87}}" The user doesn't give the ...
7
votes
2answers
134 views

Tensor product formula

Recently, I wanted to use C to implement the following formula: $$\mathbf S(u,v)=\sum_{r=i-p}^{i}\sum_{s=j-q}^{j}N_{r,p}(u)N_{s,q}(v)\mathbf P_{r,s}$$ Namely, $$ \left(N_{i-p,p}(u),\cdots,N_{i,p}(...
3
votes
1answer
23 views

Profit sensitivity analysis in base R

Using base R, I've conducted a simple profit sensitivity analysis, i.e. measuring the impact on profit if there is a change in price, variable cost per sale, unit sales or fixed costs assuming that ...
3
votes
1answer
43 views

Pretty print a 2D matrix in C (numpy style)

Works for any 2D matrix represented by a 1D array. Comments and criticism welcome. Also wondering whether the code can be made shorter. It's really messy right now. ...
1
vote
1answer
106 views

Horizontally concatenating the entries of two matrices, and padding with NaNs

I have two matrices a and b that have, on each line, some values (null or not) and then a bunch of zeros at the end. I want to ...
5
votes
2answers
73 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: ...
2
votes
1answer
68 views

Predict new ratings for each user based on their pearson correlation with other users

I am new to R and programming. I have a set of ratings for 45000 users and 40 odd movies. I need to predict new ratings for each user based on their pearson correlation with other users. I also need ...
3
votes
1answer
74 views

Counting matrix elements that have “4” or “5” as a neighbor

I have a matrix (500x500) of integers. For each entry, I need to look at its surrounding neighbours (so 8 elements) and determine what the integers are, and run a function on these integers. Here ...
0
votes
1answer
34 views

Assign values to a matrix based on the location of non-zero elements in another matrix

I have a matrix, A containing ones and zeros. I want to create a new matrix B where the non-zero elements are in the same ...
1
vote
1answer
115 views

Merging two square matrices

I would like to optimize a snippet of code, which uses a multiple nested if statements. I am looking for a formula to make it as a combination of multiple arrays ...
5
votes
1answer
89 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 ...
3
votes
1answer
88 views

Print matrix in spiral order

I have a task formulated like this Please print a matrix in spiral order, clockwise from outer rings to inner rings. I decided to implement it in Clojure. ...
3
votes
1answer
63 views

Symmetry analysis for atom arrangements in a crystal

For a while now I've been meaning to post some of my Haskell code here so that someone can tell me what parts of the language/base library I've been completely overlooking. This is the first thing I'...
2
votes
0answers
74 views

Find minimum distance in matrix

Challenge URL: http://acm.scu.edu.cn/soj/problem.action?id=3330 Windy has a matrix A with size N*M which only contains 0 or 1. The distance between Axy and Apq is: |x-p| + |y-q| Can you help ...
0
votes
0answers
28 views

Finding largest sum of submatrix

I found a way to output the biggest sum of square submatrix, but it should work faster. Can someone suggest a better way? ...
2
votes
2answers
69 views

Print out a Zig-Zag Matrix in Haskell

My task is to code something that prints out this: This is what I have done so far. ...
1
vote
0answers
48 views

Cuda C Matrix Compression

I am using Cuda to learn and implement a CSR matrix compression algorithm. What can I do better relating to C's best practices? main.c: ...
0
votes
2answers
98 views

google foo.bar max path algorithm puzzle optimization [closed]

I got a programming puzzle described as follows: Save Beta Rabbit Oh no! The mad Professor Boolean has trapped Beta Rabbit in an NxN grid of rooms. In the center of each room (except for ...
1
vote
0answers
43 views

Get vertical acceleration from rotation vector and accelerometer values

My goal here is to calculate the acceleration towards the ground, which I call "vertical acceleration". This seems to be working OK for the most part, except when there is a lot of rotation going on ...
2
votes
1answer
55 views

Spiral a matrix of size NxN filled with integers from 1 up to and including n^2

I have written a solution in Clojure for the following question: When starting from the number 1 and adding three numbers on each row a 3x3 matrix is formed as follows: ...
0
votes
1answer
25 views

C function for copying array into matrix

I want a matrix that can grow dynamically and build up a structure in RAM as input arrives from standard input och terminal (shell). First I tried with a matrix like ...
0
votes
2answers
63 views

Effective Python 2/3 two-dimensional array initialisation

Recently I noticed that the idiomatic python two-dimensional array initialisation is extremely slow. I am wondering, is there a good, proper way of doing this simple task fast? Also, are those two ...
2
votes
1answer
50 views

Expanding pixels in an image

Custom class Image takes a 2-D array of 0's and 1's upon initialization. Method transform returns a modified array by modifying 0's adjacent to a 1, such that ...
2
votes
0answers
29 views

Picking seats in a matrix

I'm trying to write a Python class that creates a matrix of zeros, then uses a random number generator to pick 'seats' on the matrix. It changes the zero in that seat to a one, until the matrix is all ...
2
votes
1answer
73 views

Project Euler problem #11 - Largest product in a grid

I have recently solved the following Project Euler problem: In the 20×20 grid below, four numbers along a diagonal line have been marked in red [here bold]. ...
3
votes
0answers
60 views

Matrix template with basic operations and utilities

I implemented a basic Matrix class for additions of matrices, multiplication of them, and multiplying every entry of matrix by constant, ...
3
votes
0answers
48 views

Analysis of TV station preferences for various demographic groups

I have a notebook here which details my code and may be more legible. I worked on a project that flattens a table that initially looked like this (this is table1): ...
0
votes
2answers
47 views

Simple Matrix Rotation

I needed to rotate a non-square matrix in my program to transpose some spreadsheet data and decided to make a function to rotate 90, 180, or 270 degrees. It doesn't rotate the matrix in place, but ...
6
votes
1answer
58 views

Matrix Diagonal Difference

Problem Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals. Input Format The first line contains a single ...
1
vote
2answers
49 views

Generic matrix in Java supporting arbitrary rotations in constant time

I have this generic "matrix" holding elements of arbitrary type. It supports any horizontal or vertical rotations (of any step size) in \$\mathcal{O}(1)\$. See what I have: ...
1
vote
1answer
137 views

HPC kernel for DGEMM: compiler v.s. assembly

This is a correct version, for computing a small matrix multiplication: C += A * B, where C is ...
5
votes
1answer
134 views

Matrix rotation

Continuing on my VB.NET quest, I came across this slightly more challenging problem. You are given a 2D matrix, a, of dimension \$M\$x\$N\$ and a positive integer \$R\$. You have to rotate the ...
3
votes
1answer
40 views

Find zeroes in a matrix

I am looking for the elements that are zeroes in a square matrix (of size n), as a list of pair. I don't really like the following code, some condition seems ...
1
vote
1answer
52 views

`Maybe` handling in Matrix manipulation in Elm

I'd like to learn if my rewrite is worse than the original, less clear or less "idiomatic". I've found this code that handles updating two dimensional matrixes in Elm: ...
3
votes
1answer
40 views

Putting a matrix from a text file into a list

I'm trying to read a text file with matrix and put it in a list, but I am using two loops here and I want my function to be faster. ...
1
vote
1answer
79 views

Reading a CSV file containing a dataset of 8×8 images

I am trying to implement a machine learning algorithm (k-nn for example). But before I attempt to do that I was hoping for some feedback on my current Main class, which essentially builds 8×8-pixel ...
8
votes
0answers
258 views

Decompose polarimetric SAR covariance matrices in MATLAB

I want to apply the following code on 3 images of the sizes 676×718, 1430×1440, and 5576×9444, but the code is too slow even for the 676×718 image. ...
3
votes
2answers
49 views

In matrix of sub-matrices, select diagonal indices of off-diagonal submatrices

Let's say I have a square matrix of size (n*m) x (n*m) that is composed of n x n sub-matrices, with each submatrix being a square of size m x m. I want to select the diagonal indices of the off-...
4
votes
1answer
72 views

Multiplying square matrix with C pthreads (POSIX threads)

I'm a student, and I'm trying to make the product of two square matrix with some threads in the soup. I've already worked on some fast single-threaded product (with some cache-friendly tricks), and I'...
2
votes
1answer
39 views

Measuring the distance between NumPy matrixes

This takes two sets of five random points stored as a NumPy matrix, and then calculates the NumPy matrix between a point of the first set and a point of the second set. While the code works, I feel it'...
3
votes
1answer
65 views

Vectorising orthogonal-triangular decomposition for 3D matrix

I am trying to optimise the computation time of my code (for the second time after a first optimisation that gives very good results). Currently, this code is very time-consuming depending on the size ...
6
votes
1answer
125 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? ...
1
vote
2answers
203 views

Rotate matrix 90 degrees clockwise

Please suggest improvements and a possible better way of doing it in place. ...
-2
votes
1answer
84 views

In matrix, if a zero is found, make its row and column to all zero

I am making an ArrayList, keeping note of all the indices where zero has occurred. Later on, I am taking out the indices from ...
2
votes
1answer
64 views

Matrix column switching

I'm currently working in the math library for a game framework that I'm writing and am working to improve some functionality that was affected during a refactor. Formerly, my ...