Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

0
votes
2answers
70 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: ...
5
votes
1answer
32 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 ...
0
votes
1answer
75 views

Multiplying two arrays

I would like to ask how to 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 ...
2
votes
1answer
54 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 ...
8
votes
3answers
499 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 ...
3
votes
2answers
69 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. ...
-1
votes
0answers
24 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 tp target for a Knight. If it is not ...
0
votes
1answer
22 views

Clockwise rotate a matrix in Scala

Given a matrix, clockwise rotate elements in it. Examples: ...
1
vote
2answers
30 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: ...
3
votes
1answer
77 views

Strassen Vinograde Algorithm

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'...
2
votes
1answer
95 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) ...
0
votes
1answer
71 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 ...
2
votes
1answer
59 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....
2
votes
1answer
62 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 ...
1
vote
1answer
81 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 ...
2
votes
0answers
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. ...
1
vote
1answer
87 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 ...
12
votes
1answer
1k views

Looking for a way to create a particular matrix in python in a less amount of time

I want to create a matrix like this in Python: $$ \begin{pmatrix} 0 & 0 & 0 & 0 & 1 & 1 & 1 & 1 & 2 & 2 & 2 & 2 & 3 & 3 & 3 & 3\\ 0 & 1 &...
6
votes
2answers
109 views

First template class - Matrix functions

This post has been answered and updated. This was the first time I've ever written a template class. I've spent probably a bunch of times re-writing matrix code for different types, different ...
3
votes
1answer
47 views

Mark positions attacked by a queen on a chess board

Problem - Given a chess board and the position of only one queen piece in it, mark all the position where the queen can move with X. Kindly review this Scala code and suggest improvements. ...
2
votes
0answers
61 views

C++ matrix operations

Not much formal education in programming. One year in school. We did C++ classes for most user defined objects. I've written a few different class variations for matrices but wonder about how useful ...
1
vote
1answer
46 views

Convert a type u16 number to a matrix (Vec<Vec<u8>> or array) of 4 x 4

I am a Rust newbie and I am not familiar with all the iterator options. This is what I have so far. How can I make this better or at least avoid collecting twice into a Vec? ...
3
votes
1answer
61 views

Vectorizing matrix operation instead of for loop in circular matrices

I have a vector \$X_k\$ and a matrix \$Y_{k,j}\$, where \$k \in \{1,\dots,K\}\$ and \$j \in \{1, \dots, J\}\$. They are circular, meaning that $$\eqalign{X_{k+K} &= X_k \\ Y_{k+K,j} &= Y_{k,j} ...
2
votes
1answer
69 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 ...
0
votes
1answer
104 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 ...
3
votes
1answer
74 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: ...
5
votes
1answer
346 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 ...
11
votes
4answers
4k 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 ...
3
votes
1answer
75 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 ...
2
votes
1answer
58 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 ...
4
votes
1answer
268 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, ...
1
vote
1answer
24 views

Creating the design matrices for a canonical correlation analysis

I have this code to generate symmetric matrices for testing how the design of the canonical correlation analysis I am performing works out. This is a extension of this solution Each row of the matrix ...
-1
votes
1answer
60 views

Combine Matrix Columns JavaScript

I did this Codepen to combine all the columns from one matrix in JS. ...
1
vote
1answer
56 views

Extract numerics from matrix A with logical matrix B

I have a matrix A containing numeric values and a matrix B containing 0/1s: ...
2
votes
2answers
59 views

Eigenvector calculation involving three matrices

Code performs well for small matrices, but gives memory error for large matrices of size 63000x93000, even when I am using server with memory of 64GB, space 100GB, swap 40GB. ...
2
votes
0answers
42 views

Dijkstra in JavaScript

I am writing the solution of Dijkstra's algorithm in JS. This is what has happened so far. I need to make it so that the choice of nodes is by recursion. Tell me how to do this better. ...
0
votes
2answers
51 views

Simple implementation of nxn Dense Matrix in Java

So far this is what I have completed. Still working on these two methods boolean isIdentityMatrix(DenseMatrix matrix); boolean isInvertible(DenseMatrix matrix); Suggestions are appreciated. Thanks. ...
1
vote
1answer
33 views

Extended matrix generation

I am extending a matrix with some calculated values. This code runs very slowly. Is there a way to vectorize this with slice and ...
5
votes
1answer
127 views

Determinant of a matrix of doubles

I have been working with some matrix functions and need the determinant. I have looked at several examples, but they all seem to use a hard coded size for the matrix, or calculate for a matrix of int, ...
2
votes
0answers
55 views

CUDA kernel to compare matrix entries, weighted with a pattern

I wonder if it's possible to optimize this code in CUDA. Could I get any hints how to? Equivalent algorithm runs faster in Matlab for me, but there I'm doing matrix operations. Compution I'm not ...
3
votes
2answers
72 views

Demonstration of Find Vowel Square

Have the function VowelSquare(strArr) take the strArr parameter being passed which will be a 2D matrix of some arbitrary size filled with letters from the alphabet, and determine if a 2x2 square ...
-3
votes
1answer
1k views

Sum of diagonal elements in a matrix [closed]

The idea is to calculate sum of diagonals example [[1,2,3],[4,5,6],[7,8,9] the correct answer would be [1,5,9][3,5,7] = total 30 ...
0
votes
1answer
75 views

R Function to Generate Predictions from Ratings and Save Results

I am trying to generate predictions using the function below in combination with sapply. My actual datasets are very large, I am attempting to make 1.5 million predictions with this function and it is ...
5
votes
0answers
231 views

Codewars: N-dimensional Von Neumann Neighborhood in a matrix

Task: For creating this challenge on Codewars I need a very performant function that calculates Von Neumann Neighborhood in a N-dimensional array. This function will be called about 2000 times The ...
1
vote
0answers
249 views

MIPS Assembly Program to access elements in the 4x4 matrix, row or column-major oder

This MIPS Assembly program will make you access the elements in the 4x4 matrix in either row or column-major order i.e. accessing all elements row by row or column by column. Output is posted below ...
5
votes
1answer
265 views

A Simple Interactive Program that Can Solve A Linear System of Equations

So I was just reading my algebra-precalculus textbook, and learned that matrices can be used to solve systems of equations. Since the whole process seemed so algorithmic, I wondered if I could ...
2
votes
1answer
520 views

Print concentric rectangular patterns

I am solving interview questions from here. Problem : Print concentric rectangular pattern in a 2d matrix. The outermost rectangle is formed by A, then the next outermost is formed by A-1 and so on....
0
votes
3answers
264 views

Calculate median of a matrix

I am solving interview questions from here. Problem : Given a N cross M matrix in which each row is sorted, find the overall median of the matrix. Assume N*M is odd. Note: No extra memory is ...
3
votes
2answers
113 views

Math matrix, mainly for graphics

I wrote a matrix library to replace my old matrix library. I was using my old matrix library to do basic operations for 3D rendering but that library grew old and now I'm seeking to replace it. I'm ...
6
votes
1answer
1k views

Gaussian Elimination with Pivots

I'm pretty new to python, and coding in general. For practice, I've written the following code, which uses Gaussian reduction to solve a system of linear equations. ...