Hot answers tagged

32 votes
Accepted

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

The NumPy Reference should be the first place you look when you have a problem like this. The operations you need are nearly always in there somewhere. And functions that you find while browsing the ...
Gareth Rees's user avatar
  • 49.6k
23 votes

Python 3 function to rotate an image 90°

You can use NumPy module that's good with arrays and matrices. It has a built-in for exactly that purpose - ...
Divakar's user avatar
  • 896
22 votes
Accepted

Python 3 function to rotate an image 90°

I believe the time complexity is \$O(n^2)\$, but I'd like to know for sure There's a general method for figuring out the time complexity for a piece of code, which is to annotate each line with the ...
Gareth Rees's user avatar
  • 49.6k
20 votes
Accepted

A library to do maths with matrices written from scratch

Compared to Python's NumPy, my matrix multiplication is quite a bit slower. Can it be made faster without using sophisticated matrix multiplication algorithms like Strassen's? One issue is that you ...
Dan Oberlam's user avatar
  • 7,784
18 votes
Accepted

Matrix class in C#

I like that your braces and indentation is beautifully consistent. But, this is C#, and your Java is showing ;-) - Kudos for the mostly-consistent PascalCase type ...
Mathieu Guindon's user avatar
17 votes
Accepted

AVX SIMD in matrix multiplication

The biggest performance problem (for small matrices), and a common mistake, is doing this: ...
harold's user avatar
  • 9,464
15 votes
Accepted

Enter my Matrix

I will mostly focus on performance in this review because you have specifically asked for it and the other reviews did not cover it yet. Performance The first thing to do when optimizing for ...
5gon12eder's user avatar
  • 4,250
15 votes
Accepted

Triangle area computation and linear transformations

Here are a few of the high- and low-level ideas: too many comments. Remember, comments tend to age and outdate, they need to be maintained as the code changes. And, if they are over-used, they hurt ...
alecxe's user avatar
  • 17.2k
12 votes
Accepted

Python algorithm that converts array-like data into MathJax

This looks like a handy tool to have around, maybe we can make it even better. Style As per the official Python Style Guide (often known by his nickname PEP8), keyword-arguments of functions should ...
AlexV's user avatar
  • 7,244
11 votes
Accepted

Matrix multiplication in Java

In addition to what Hosch has told you: Make use of try with resources You utilize several classes which implement the Closable interface, but aren't explicitly ...
Legato's user avatar
  • 9,819
11 votes

SIMD matrix multiplication

Restructure into a function to make it DRYer Right now the structure of your code is pretty unpleasant, not very DRY, etc. The first thing I'd recommend is restructuring this to work in a function. ...
Dan Oberlam's user avatar
  • 7,784
11 votes

Matrix class in C#

A bug: Transpose does data[i, j] = data[j, i];, but it returns a new matrix, it's not supposed to change the matrix in-place, ...
harold's user avatar
  • 9,464
11 votes
Accepted

Calculate determinant of a matrix using cofactor expansion

It's much worse than cubic time. At every "level" of the recursion, there are n recursive calls to a determinant of a matrix that is smaller by 1: ...
harold's user avatar
  • 9,464
10 votes

A library to do maths with matrices written from scratch

for loops in C++ In C++ you can declare the loop variable in the statement instead, like this: ...
janos's user avatar
  • 111k
10 votes

Enter my Matrix

boolean validIndices looks suspicious: it never returns false, so why bother to return anything at all? Notice that it also ...
vnp's user avatar
  • 56.2k
10 votes
Accepted

4×4 matrix multiplication

Avoid using namespace std This can cause name collisions because it adds every name in the std namespace to the global ...
Null's user avatar
  • 1,433
10 votes
Accepted

Rotate an N × N matrix 90 degrees clockwise

Are you up to date? There is really not much to the problem and there are a variety of solutions. It is also hard to know what the interviews are looking for. For some it is knowledge of latest ...
Blindman67's user avatar
  • 21.6k
10 votes
Accepted

Code to multiply matrices together

Both of the other answers make some very good points, especially when it comes to replacing vector. Two dimensional vectors are particularly iffy because the whole lump of memory will not be ...
Josiah's user avatar
  • 5,976
9 votes

A library to do maths with matrices written from scratch

Regarding the first question What can be done to make my style better? I've noticed in your Matrix.cpp file the class member variables are referred to inconsistently throughout the different ...
Chase's user avatar
  • 273
9 votes

Python algorithm that converts array-like data into MathJax

Python's string formatting has come a long way from the "%s" formatting days. Nowadays classes can even determine on their own how to handle format specifiers. ...
Graipher's user avatar
  • 40.9k
9 votes

Template Matrix Class: implemented some basic functionalities

Overview Potentially not very efficient. I have seen other Matrix libraries not do the actual computation until the value is needed. So what is passed around is a Matrix wrapper that contains ...
Martin York's user avatar
  • 94.6k
8 votes
Accepted

Matrix template with basic operations and utilities

A bug Your multiplication algorithm has a bug: temp[i][j] += matrix[i][k] * rhs[j][k]; Your version will produce $$ \begin{bmatrix} 1 & 2 \\ 3 & 4 \...
coderodde's user avatar
  • 27.5k
8 votes
Accepted

Implementing a tensor product formula

Readability & Maintainability Right now your code is a bit hard to read. A way to greatly help this would be to use better variable names. Put the variable declarations to separate lines and ...
syb0rg's user avatar
  • 21.8k
8 votes
Accepted

Read matrix from file, the C++11/14 way

I see some things that may help you improve your code. Use the required #includes The code uses std::vector which means that ...
Edward's user avatar
  • 66.4k
8 votes

Transpose function

Here are some things that may help you improve your program. Declare variables only where needed Old-style C required all variables to be declared at the top of the function in which they were used, ...
Edward's user avatar
  • 66.4k
8 votes

Transpose function

Reconsider ansi -ansi is equivalent to C89, which is many versions behind the current standard (C99 -> C11 -> C17). C99 is ...
Reinderien's user avatar
  • 60.4k
8 votes
Accepted

A Matrix Library in C++;

using namespace std; Never do that; certainly not in a header - that inflicts the harm onto every source file that includes the header. Prefer to include your ...
Toby Speight's user avatar
  • 74.4k

Only top scored, non community-wiki answers of a minimum length are eligible