# Tag Info

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 ...
• 49.6k

### 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 - ...
• 896
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 ...
• 49.6k
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 ...
Accepted

### AVX SIMD in matrix multiplication

The biggest performance problem (for small matrices), and a common mistake, is doing this: ...
• 10.1k
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 ...
• 17.3k
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 ...
• 7,270

### 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, ...
• 10.1k
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: ...
• 10.1k
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 ...
• 1,433
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 ...
• 22.2k
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 ...
• 6,006
Accepted

### Python matrix class

Transposes the current Matrix, modifying the underlying arrays object. You can do it that way. However, it commonly happens in linear algebra code (especially when transcribing formulas from math ...
• 10.1k
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 ...
• 66.5k

### 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. ...
• 41k

### 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 ...
• 95.4k

### Create a snail matrix

It is great that you provided example code for us to run. The code layout is good and the implementation is compact. Add a docstring to the top of the code to describe its purpose. For example, the &...
• 3,942
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 \...
• 28.9k
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 ...
• 21.8k

### 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, ...
• 66.5k

### Transpose function

Reconsider ansi -ansi is equivalent to C89, which is many versions behind the current standard (C99 -> C11 -> C17). C99 is ...
• 62.8k
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 ...
• 77.3k
Accepted

### Generic matrix library in Java

Dense matrix multiplication in 15572 ms. Going by the demo code I assume this was the product between two 1000x1000 matrices. By my estimate based on old code the raw operations by themselves could ...
• 10.1k

### Matrix Class Implementation

Missing all includes and the C++ version, so I had to make some guesses to get this to compile. assert(rows >= 0); assert(cols >= 0); OK, but ...
• 10.1k

### Matrix Class Implementation

Use std::mdspan Since you tagged the post c++23, consider using std::mdspan in your code. Not only can you use that internally ...
• 58.7k
Accepted

### Snail matrix in Java

Expose behavior / Don't manipulate the internal state directly Object-orientation is about exposing behavior (not data), defining methods that are tailored for the problem at hand, that are meant to ...
• 1,339
Accepted

### Rotate Matrix using Python

You can use much simpler algorithm in python: Transpose matrix: zip(*matrix) Inverse rows in transposed matrix (equals rotation right): ...
• 86