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
1answer
105 views

Get column of a matrix python with index operator

How can I refactor this code to generalize the argument parsing? I feel like this code can be better but I can't find a way. The usage syntax of the index operator is similar to the NumPy indexing ...
5
votes
1answer
819 views

Type safe, easy to understand matrix multiplication

I always hated matrices (as they are taught in those linear algebra course books that I have browsed), because it's an obscure way of saying "a tuple of linear functions of same arity". It is very ...
2
votes
3answers
801 views

Find the longest path in a matrix where each step has entries that differ by 1

Given an N*N matrix that all numbers are distinct in it, the function should find the maximum length path (starting from any cell) such that all the cells along the path are in increasing order with a ...
2
votes
2answers
1k views

Find total number of paths in a matrix of 0's and 1's

I am working on a program which states that: You are given a 2-D matrix with M rows and N columns.You are initially positioned at (0,0) which is the top-left cell in the array. You are allowed to ...
1
vote
1answer
3k views

Generating a word bigram co-occurrence matrix

I have written a method which is designed to calculate the word co-occurrence matrix in a corpus, such that element(i,j) is the number of times that word i follows word j in the corpus. Here is my ...
6
votes
1answer
158 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 ...
5
votes
1answer
343 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 ...
7
votes
2answers
79 views

Rotating a matrix in ANSI C

I have this C program that rotates a character matrix. This is a straightforward rewrite of this Java implementation. Both versions do additional \$\Theta(mn)\$ preprocessing and require \$\Theta(mn)\$...
3
votes
0answers
42 views

Deriving incremental feature representations for bit flips

Given a boolean 3D matrix and a set of actions specifying bit flips at certain positions, a set of resulting matrices can be obtained, one matrix for each action, as if executing each bit flip ...
7
votes
2answers
1k views

Efficiency and techniques for Matrix class that inherits from Python's list

I have a class named Matrix, this class inherits from Python's list. The class currently can ...
6
votes
1answer
74 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 ...
2
votes
2answers
591 views

HackerRank - Queens Attack II - Java

The problem definition can already be found here. Given a chess board with dimensions n × n (where n is up to 100000) and the (r, c) positions of various obstacles, how many squares can a queen at a ...
2
votes
1answer
336 views

Spiral filling an existing matrix in their respective positions in descending order efficiently

Question: Sort the boundary elements in descending order using any standard sorting technique and rearrange them in the matrix. Calculate the sum of the boundary elements. Display the original matrix,...
3
votes
3answers
5k views

Rotate an N × N matrix 90 degrees clockwise

Given the problem from "Cracking the coding interview" Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees ...
6
votes
1answer
7k views

4×4 matrix multiplication

This is a simple C++ code with a function mult to multiply matrices. This can easily be generalized for any \$n \times n\$ matrix by replacing ...
3
votes
1answer
47 views

Create a matrix where if an element in an M×N matrix is 0, its entire row and column are set to 0

How is my implementation? Are there improvements I can make to the variable names or any edge cases I might have missed? ...
0
votes
1answer
159 views

Greedy adaptive dictionary (GAD) for supervised machine learning [closed]

For my project in machine learning supervised, I have to simplify a training-data and I have to use this technique at page 5 of the document. Pseudocode algorithm My code (numbers are the steps): <...
8
votes
2answers
584 views

Short square matrix class in C++ using an array

I'm a novice at C++ in comparison with other languages, so as an exercise I wrote a square Matrix class that doesn't use STL. ...
1
vote
1answer
808 views

Rotating a matrix in Java

Introduction This program is about rotating a matrix. For example, let the matrix be abcde fghij klmno pqrst Now, after rotating two steps clockwise we will ...
6
votes
1answer
582 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 ], ...
3
votes
3answers
5k views

Multiplication of any two matrices using lists and for in loop

I've just started learning Python and after few lessons I grasped the idea of lists and loop and decided to create my first project. Objective: Calculate multiplication of any two matrices from user'...
3
votes
0answers
108 views

Haskell Laplace determinant

I have written a code in Haskell that calculates the determinant of a matrix using the laplace expansion. As I have just started learning Haskell, I would like some opinions on how well (structured) ...
4
votes
2answers
2k views

Calculate co-occurrences of some words in documents dataset

It's a function to calculate the co-occurrences of some words in a news dataset, such as Techcrunch, Wired. The words list could be locations, products or people names. Words list example: ["New ...
2
votes
1answer
138 views

Competition - Qualifications - E - Matrix distance

2 types of query: add value to x y output the sum of \$value*(|a - x|+|b-y|)\$ for every pair(a, b, v). In the start you are given \$n\$ (number of querys), \$m\$ (maximal dimension for square ...
1
vote
1answer
272 views

Recursive matrix multiplication

I've just written a recursive matrix multiplication and I want to know my mistakes or problems. Is there a better way doing this? ...
2
votes
0answers
279 views

Matrix inverse by elimination

Because I had trouble in finding a reliable source on the internet for the matrix inverse algorithm using Gaussian elimination, I wrote one myself. Matrix.h ...
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): ...
1
vote
2answers
62 views

Calculating the connectance of a matrix iteratively

I have a performance issue in R. I have a function that iterates over a dataframe for different levels of "site" and "method". The function samples 1:1000 interactions (rows), converts these to ...
4
votes
1answer
182 views

C++ template functions to partially implement Python numpy ndarray limited to 1d and 2d

I just read a book on creating a neural network. The book uses Python. I wanted to port this to C++. In order to do that I had to create template functions to implement some of the ...
6
votes
1answer
255 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 ...
7
votes
2answers
1k views

Triangle area computation and linear transformations

I have a task to learn how to write clear and understandable documentation of written code in python. Please, can you give me a feedback to attached code below? I need to know if the code and comments ...
1
vote
0answers
115 views

Performing FFTW double[2] on images of type cv::Mat

I've two different types of variables: cv::Mat and array of type double[2] so I do quite lot of copying between the two types. I ...
2
votes
0answers
325 views

class for Block Compressed sparse Row storage

Here my Block Compressed sparse Row storage class, I have some doubt about the constructor that use a std::vector<std::vector> for store the initializer list ...
1
vote
1answer
348 views

Fast affine transformations of many 3D points by one 3×4 matrix

I wrote a function to batch-transform 3D vectors by a single 3x4 matrix using SSE2: ...
3
votes
1answer
78 views

Computing Nth element of a series

I am computing Nth element of the the sequence: \$a_n=-2a_{n-1}+a_{n-2}+2a_{n-3}\$ Initial values are \$a_1=-2\$ \$a_2=6\$ \$a_3=-8\$ Code ...
2
votes
2answers
748 views

Modified compressed sparse row matrix code

I've implemented a Modified Compressed Sparse Row matrix class! The class works, but I think that some part of the code is quite crap. There are two passages and the whole code became too expansive ......
3
votes
0answers
150 views

Propagation solver in C++ using discrete Hankel transform

I wrote a small program which propagates light pulses using a discrete hankel transformation (based on A quasi-discrete Hankel transform for nonlinear beam propagation, You Kai-Ming et al., 2009. It ...
1
vote
0answers
54 views

product member of CSC matrix class

I'm implementing a CSR and CSC class! I found a lot of algorithms for computing a CSC * vector product but I didn't find any routine for the CsC * CsC matrix product, in order to save time when the ...
3
votes
0answers
2k views

Matrix multiplication project using multithreading in java

Below is my code of matrix multiplication in Java. It has both implementation of matrix multiplication- one without multi-threading and another one using multi-threading. For multi-threading ...
1
vote
0answers
2k views

Parallel matrix multiplication in Java with streams

This StackOverflow post highlights how to do matrix multiplication using Java's stream. With Java streams, there is a new way to enable concurrent threading with the Java's parallel stream. ...
5
votes
3answers
1k 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. ...
4
votes
1answer
7k views

Matrix multiplication using functions in C

This exercise surprised me a little bit. I did not expect that gcc (GCC 6.3.0 in the MinGW suite) would use the C11 standard by default, which I realised after I ...
6
votes
1answer
1k views

numpy performance of norm calculation using variable dimension

I am looking for advice to see if the following code performance could be further improved. This is and example using a 4x3 numpy 2d array: ...
1
vote
1answer
205 views

Map square coordinates in matrix to flat array indices without hurting performance

I'm more like playing and the problem I'm going to demonstrate is a learning task, so to speak, not something I really need to solve. Imagine having a matrix of data. You chose square in it and ...
6
votes
2answers
3k views

AVX SIMD in matrix multiplication

I have coded the following C function for multiplying two NxN matrices and using AVX vectors to speed up the calculation. It works but the speedup is not what is to be expected(some scalar code is ...
3
votes
1answer
185 views

Normalization, division and reshaping processes on an HDF5 file

I performing a set of division operations and reshaping on a HDF5 file. As my datapoints is around 4000 in number it takes around a minute. I will be adding more data, which will further slow my ...
5
votes
2answers
279 views

Array transposition

The task: take a byte[][] and transpose it. The complication: the original array is a result of a partition operation that might not be even, so the last subarray ...
4
votes
3answers
449 views

Portable multithreaded matrix multiplication in C

I essentially took this progam, and made it compile and run on Windows too. Also, I incorporated some nice points made by Toby Speight. matrix.h ...
3
votes
1answer
854 views

Multithreaded matrix multiplication on Unix in C

I have this program for comparing serial and parallel matrix multiplication algorithms: matrix.h ...
5
votes
1answer
739 views

Improving the manipulation of 2D Arrays for an easy challenge on HackerRank with Python 3

I am practicing some exercises on HackerRank in order to improve my skills on Python3. I am doing the 30 days challenge. There is one challenge involving matrices. I was able to pass the test cases ...