# 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.

549 questions
Filter by
Sorted by
Tagged with
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 ...
2k views

### Find diagonal positions for bishop movement

In a chess board, I need to find the diagonals a bishop can move on, and more specifically, the coordinates of those squares. So, given a grid of any size and a position in that grid (expressed in ...
3k views

### Conditional removal of columns in sparse matrix

I have a large dataset (78k instances x 490k features) that is loaded as a scipy.sparse.csr_matrix format. From this dataset I want to filter certain features (i.e. ...
3k views

### Return row or column from a 2D array

I have a 2D array class that is actually mapped to a 1D vector. For example, to obtain an element at a particular position, the code is as follows: ...
298 views

### Devise an algorithm of complexity O(N) finding No of 1's from a 2 dimensional matrix[N][N] containing 1's and 0's

Assume a 2D [n][n] matrix of 1's and 0's. All the 1's in any row should come before 0's. The number of 1's in any row I should be at least the number of 1's row (i+1). Find a method and write a C ...
83 views

### Getting saddle points of a matrix

My homework assignment: Write a function called saddle that finds saddle points in the input matrix M. For the purposes of this problem, a saddle point is defined as an element whose value is ...
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 ...
61 views

### Converting state matrices to adjacency matrices to thresholded matrices

I am currently taking part in research utilizing Naked Mole Rats. I am utilizing data analysis techniques to answer the overall question, "Can we detect certain types of naked mole rat behavior ...
612 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'...
81 views

### Function that reorders the columns of a matrix

The objective: Given an m by n matrix, I have written a function in Matlab that reorders the columns of the matrix to output linearly independent columns; other/redundant columns. Basically, it just ...
5k views

### Implementation of KNN in R

I have implemented the K-Nearest Neighbor algorithm with Euclidean distance in R. It works fine but takes tremendously huge time than the library function (get.knn). Please point out the possibility ...
146 views

### Speeding up nested for-loop analysis code

I have two matrices, the first one is mat 2000*500, the second one is 6000*500 ...
915 views

### Point in a polygon algorithm

I am implementing a Point in polygon algorithm. Inputs: M, N: size of the matrix poly: a ...
977 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 <...
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 ...
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: ...
334 views

772 views

### Optimizing a dynamic programming solution for “Oil Well”

I'm trying to solve the Oil Well problem on Hackerrank using dynamic programming and it works. However, it times out for some of the test cases. I wanted to know how this program can be improved so ...
535 views

### Optimization of matrix determinant calculation

I have this algorithm that calculates the matrix determinant using recursive divide-and conquer-approach: ...
59 views

### 4×4 cofactor in SSE

The cofactor of a 4×4 matrix can be used to convert a "regular geometry" matrix into the matrix that transforms the normals. It's an alternative to the common inverse-transpose pattern. In this post I ...
170 views

### Creation of matrix with specific attempts at the end

What I want to do is build a Slay-the-Spire-like Map. As you can see in the following image, the map is splitted in ISteps and ...
2k views

### Implementation of the Householder Transformation

I implemented the Householder transformation in Python, so that I can later use it in a QR decomposition. Unfortunately I haven't found a good concise source for reading up on the algorithm. I am not ...
577 views

### Minimum number of moves to solve “game of fifteen”

I read about this game and tried to make my own algorithm to solve this. I asked it on StackOverflow for the appropriate algorithm and logic to solve this problem. With the help of answers over ...
235 views

### How to make a matrix factorization system recommander faster?

I used and modified a matrix factorization function for a system recommender from quuxlabs.com. It works well for small sized input but when we get to large matrix it takes too much time. I was ...
204 views

### Generalized NumPy reshape function to imitate einsum syntax

I often perform a lot of reshape(), transpose() or squeeze() operations on ...
53 views

### Basic declarative style to rotate and crop an image array

I wrote a couple of basic Clojure functions (practicing a declarative style) and I was looking to get some feedback on them. You can see all the code here. Is there anything I could improve on to ...
964 views

### D3 Matrix table

I am able to develop this matrix but I think code can be improved. I am creating a map on which each rectangle may have zero through many list items with their titles (still need to add code for ...
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 ...
346 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 ...
4k views

### A Java class that prints a matrix

I am trying to learn some generic programming with Java: ...