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.

1
vote
0answers
1k 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. ...
1
vote
0answers
171 views

Haskell - Adjacency Matrix

This program is used to solve Challenge #140 [Intermediate] on /r/dailyprogrammer. The challenge is, given a input set of directed edges, print the corresponding ...
1
vote
0answers
47 views

Blurring an image using matrices

Suppose there is a very big matrix and and a small window is moving on the matrix. The small window will move right and down, step by step (means each time move one step right, or move one step down). ...
1
vote
0answers
2k views

Traceback in sequence alignment with affine gap penalty (Needleman-Wunsch)

I am working on an implementation of the Needleman-Wunsch sequence alignment algorithm in python, and I've already implemented the one that uses a linear gap penalty equation for scoring, but now I'm ...
1
vote
0answers
1k views

HackerRank - Matrix Rotation

Problem statement Given a matrix (up to 300 × 300), rotate each element R steps anti-clockwise along concentric rectangular paths (R up to 109). The algorithm is rated as hard on HackerRank. On ...
1
vote
0answers
124 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: ...
1
vote
0answers
348 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 ...
1
vote
0answers
130 views

Why does lu-factorization make my program slower?

I'm trying to calculate the smallest eigenvalue of the matrix A by using the "inverted exponentiation method" (see the code). I manage to find the smallest eigenvalue, but when I try to optimize the ...
1
vote
1answer
1k views

Is my 4x4 matrix multiplication on a 1D float array correct?

I'm trying to develop my own math library to use on a Voxel engine, but I'm worried about Matrices multiplication. Everywhere I saw people using 4x4 Matrices on a 2D Float Array but I'm using a 1D ...
0
votes
4answers
31k views

Matrix operations using classes

So I recently had a practical exam in which I was told to execute a function of a menu oriented matrix operation program using classes. The code I made was supposedly wrong as I hadn't used classes ...
0
votes
2answers
193 views

LSH hashcode generator function

For building an LSH based system in Python, I need to have a very fast calculation of the hashcode. I won't need to explain here the LSH algorithm itself, but I need help in improving performance of ...
0
votes
2answers
691 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 ...
0
votes
1answer
74 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 ...
0
votes
1answer
1k views

Eigenvalue calculation for a Java matrix library [closed]

After an interview didn't go smoothly, I decided to write my own library so that I would be better prepared if I'm ever asked about matrix multiplication again. I know that doing it in Java is going ...
0
votes
2answers
176 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: ...
0
votes
1answer
110 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 ...
0
votes
1answer
185 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 ...
0
votes
3answers
352 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 ...
0
votes
2answers
2k 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 ...
0
votes
1answer
746 views

Comparing rows of a matrix with some row vectors

I have run this program for five hours and it has not yet completed. I wonder if we can make changes to reduce the computation time. I use several for loop and this greatly increases the computation ...
0
votes
1answer
68 views

Clockwise rotate a matrix in Scala

Given a matrix, clockwise rotate elements in it. Examples: ...
0
votes
1answer
157 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): <...
0
votes
2answers
140 views

Calculating shortest possible route between two given nodes

I recently came across this problem: Heroes in Indian movies are capable of superhuman feats. For example, they can jump between buildings, jump onto and from running trains, catch bullets with ...
0
votes
2answers
90 views

Code for number of routes possible of the given length between 2 given nodes

Recently I came across this problem , here is an excerpt of it, It is well known that the routing algorithm used on the Internet is highly non-optimal. A "hop", in Internet jargon, is a pair of ...
0
votes
2answers
340 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 the ...
0
votes
1answer
87 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
91 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. ...
0
votes
1answer
64 views

Backward transformation implementation for a barrel eye lens aberration in c++ 14 (using opencv)

I've made the following backwards transformation from a "transformed" source x,y point, to the resulting index of the actual image that I have, so I can avoid black spots appearing in my barrel eye ...
0
votes
1answer
49 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 ...
0
votes
1answer
78 views

Find Row with Max zero

To find the row with max zero Matrix will have either 0 or 1 in sorted manner. ...
0
votes
1answer
531 views

Computing tangent space basis vectors for an arbitrary mesh

This is more like a share and a request than a question. I converted Eric Lengyel's code, which calculates tangents of a mesh for the purpose of texturing and normal mapping, to support SIMD. For this ...
0
votes
1answer
471 views

Finding columns of a matrix that are the same for combinations of events

How I can change this multi-loop to reduce the computation time? A is a matrix (5 × 10000) where the fifth line contains values between 1 and 50 corresponding to ...
0
votes
1answer
77 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 ...
-1
votes
2answers
598 views

Matrix multiplication of arbitrary sizes [closed]

This function is for multiplying two matrices together. It's kind of messed up because the result is actually supposed to overwrite the object that called it, or since it's ...
-1
votes
1answer
66 views

Combine Matrix Columns JavaScript

I did this Codepen to combine all the columns from one matrix in JS. ...
-2
votes
2answers
103 views

Numerical algebra using a Matrix class [closed]

I would like to make a Matrix class. Can any of you help me about this class? There are two ways: ...
-2
votes
1answer
279 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 ...
-3
votes
1answer
4k 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 ...
-3
votes
1answer
69 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: ...
-4
votes
1answer
2k views

Find element in 2D matrix where rows and columns are sorted

Elements of a matrix are given in sorted rows and columns. I want to find the element in an optimized way. First, I will get the last element of a row, which will determine if a number can exist in ...