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.

570 questions
Filter by
Sorted by
Tagged with
136 views

Matrix class with space-optimized triangular (lower and upper) variants

I've written a class for square numerical matrices (of doubles, in this case), in C++11. Since I intend to use this class later ...
67 views

Transpose of a very large matrix with fewer than 1021 rows with Python

I have a matrix of fewer than 1021 rows. I'd like to take its transpose, but it is too big for GNU datamash and awk solutions to ...
44 views

Calculating the potential of a matrix of size (424600, 55)

I have the following working code to calculate the potential of a matrix after normalizing the matrix. But it is too much time consuming. Is there a way to make this code run faster? ...
120 views

JavaScript Spiral Matrix Coding Challenge

A whiteboarding challenge: Given a 2D array (matrix) inputMatrix of integers, create a function spiralCopy that copies ...
84 views

Decomposing a matrix as a sum of two bitstrings

I chanced upon this question and came up with the following algorithm, looking for criticisms and advice on how to improve my algorithm efficiency. You are given 3 arguments: A & B are ...
77 views

Reading sparse matrix from binary file

I have binary files containing sparse matrices. Their format is: number of rows int length of a row int column index int value float Reading ...
109 views

Perturbed phase oscillator integration

I am integrating a system of perturbed phase oscillators. I define the system of equation and also the Jacobian matrix. I have to reshape the one dimensional vector of system state to a 2 dimensional ...
382 views

C++ Dataset class

C++ newbie trying to build a class to represent a dataset for the purposes of building predictive models of the form y ~ x0, x1,... Since this is version 1, I'm assuming some nice properties about my ...
57 views

Lambda based matrix

I am calling matrix implemented with a lambda "lambda matrix". The full working program: ...
314 views

Cache-optimized matrix multiplication algorithm in C

I am trying to optimize matrix multiplication on a single processor by optimizing cache use. I am implemented a block multiplication and used some loop unrolling, but I'm at a loss on how to optimize ...
564 views

Inverse mapping with bilinear interpolation on an image

The following is my solution for an inverse mapping with bilinear interpolation on an image. The original image is img and ...
111 views

Calculate huge Fibonacci Numbers in C++ using GMP and boost::multiprecision

Problem Statement Calculate the exact value of the n-th Fibonacci number, say the one-billionth. Algorithm The algorithm is based on the idea that Fibonacci numbers can be represented as 2x2 ...
84 views

About the problem of seeking matrix inverse

Recently I have solved the inverse matrix in three ways, found that their work efficiency has obvious differences. This is the case: ...
136 views

Pandas calculations per columns and per rows for very big datasets

I am using a panda's dataframe and I am doing filtering and some calculations per column and per row. The dataframe looks this: ...
131 views

Simple matrix library in C++

Today I started learning C++ and at the end of the day have made a simple generic matrix class. I'm looking for feedback on techniques and features. It's still not complete, though. But everything ...
244 views

Multiplication of 3×3 and N×N square matrices

I recently wrote a matrix module in C++. During the development process I quoted some source code and found a problem. For example, matrix multiplication: This way is suitable for all N×N matrices： ...
241 views

Blurring a given image using moving average in Python 3

I've tried solving the following HackerRank question: Write a function blur_image() that takes as a parameter an image in the form of a nested list ...
115 views

Multiplying two arrays

I would like to ask how I can make my code more simple and effective. I know that this code can be 100% better. I am supposed to load number for each array and then take the 2 arrays (4*3 and 3*4) and ...
967 views

Rotate matrix 90 degrees

I recently did problem 1.7 Rotate Matrix in Cracking the Coding Interview. I realized my code is very different than what is in the book and what I am also fining online (I'm having trouble following ...
513 views

Transpose function [closed]

I wanted to write a transpose function for N*N mat without it getting literals or #define values and I want it to compile with ...
170 views

Simple Matrix Template Class

I wanted to make a matrix template class to see if I can learn how to use templates, work on figuring out the indexing in loops, and making an interface so the user can know if an operation will work. ...
89 views

Minimum steps to reach target by a Knight In Scala

Given a chessboard of N size (square matrix), the position of Knight and position of a target, find out minimum steps (both count and exact steps) from start to target for a Knight. If it is not ...
240 views

Clockwise rotate a matrix in Scala

Given a matrix, clockwise rotate elements in it. Examples: ...
165 views

Print matrix in spiral order in Scala

Problem: Given a square or rectangular matrix, print its element in spiral order. For example, if input matrix is this: ...
152 views

I have written an implementation of the Strassen Vinograde Algorithm, but it's running slowly because of recursive creation of static arrays. I know that dynamic arrays would solve this problem, but I'...
478 views

SIMD product of a 4×4 matrix and a vector

I wrote a matrix class for use in a ray tracer. I already have a 'scalar' version up and running, but now I'm trying to rewrite it to use Intel SIMD Instrinsics. I realize my compiler (clang-7.0.0) ...
99 views

Matrix arithmetic operations

I am currently attempting to implement Matrix Math for another project I am working on. However, I am not sure whether this implementation will work. Can someone please tell me if there are any ...
81 views

Applying a function to each row of a matrix

My goal is to apply a function func1 to each row of the matrix input and then return a new one resulting from the transformation....
88 views

Finding valid path on 2D Grid

I got a 2D grid (n x n matrix). The user selects his player in this 2D grid and after that selects another node in this grid to mark his destination position. The player is allowed to move ...
125 views

Template matrix class, second version

This is my first matrix class which I updated after already asking here already. The updated code is below. Are there any suggestions regarding member function parameters? Is there a convenient ...
31 views

MinMax product for large matrices

I created this program which runs with no error, but I'd like to have some comments if it is possible to optimize it, since I need to run the program with N = 3200. ...
2k views

Basic beginner's matrix class in Python

This is my first class. I've been working a while on it, some functions are future ideas and are right now just bare bones and intended to be worked on later. I'm really looking for a good review of ...
1k views

329 views

2D Matrix with jagged array isn't faster than one with a multidimensional array

I was trying to use Math.Net's dense matrix class. But, it doesn't support int. So, I have to create a wrapper for a jagged 2d array. I knew that jagged arrays ...
61 views

Applying a function to columns of two matrices producing their combinations

I made a short snippet for applying a function f that takes two arguments (vectors) to columns of two matrices producing all possible combinations of those columns. ...
252 views

Drawing concentric circles to console

This prints out a triple layer circle with 12 points per circle and finds the points across a grid. I had a really hard time with this and I'm planning to implement a lot more code but I don't want ...
249 views

Find the longest line in 2D (MxM) array (vertical, horizontal, or diagonal)

Find the length of the longest line with given square (MxM) matrix. (vertical, horizontal, or diagonal allowed) (Length of the longest line = number of consecutive 1's) i.e.) input: ...
1k views

Determinant using Gauss Elimination

We had a question in examination to compute determinant of general square matrix. Now I had made the normal program using Laplace Formula of determinant, ie, recursive solution. Now I was thinking of ...
9k views

Python 3 function to rotate an image 90°

A coding challenge that rotates an image 90 degrees counterclockwise. The image is represented as an array matrix. I believe the time complexity is O(n2), but I'd like to know for sure, as well as any ...
92 views

Custom matrix object in C++

I have been getting back into C++ today, after a few years of Python and R. I am completely rusty, but decided to create a matrix object to re-familiarise. In reality I wouldn't use this class, since ...
61 views

Fast algorithm for any(M==2)

I want to find a quick way to see if a matrix M has at least one value that is, say, 2. In R, I would use any(M==2). However, this computes first ...
292 views

Group-wise deviations from means / centering with dplyr vs. data.table

I am trying in R to "center" a matrix (i.e. remove mean) group-wise (i.e. remove group means for each variable). Input is a matrix (including the grouping variable), and output is the same matrix, ...