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.

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.

Matrices with the same number of rows and columns can be added or subtracted element by element. But the rule for matrix multiplication is that two matrices can be multiplied only when the number of columns in the first equals the number of rows in the second.

Types of matrices

A matrix can be represented as a 2-d (two dimensional) array in any programming language, where one of the two dimensions defines row elements of a matrix, and other dimension defines column elements of the matrix.

Tag usage

The tag can contain programming related problems in implementing matrices. Questions in this tag will be related to a multidimensional array, so these questions can also be tagged with . Please avoid mathematical problems on stackoverflow (use the Mathematics Stack Exchange site instead).

Also note these related tags:

Read more

40841 questions
7
votes
2 answers

Using a vector as column-indices into rows of a matrix, in Octave

Let's say I have a matrix A and a vector B. Is it possible to use the values in vector B as indices to select one value from each row in matrix A? Example: A = [1, 2, 3; 4, 5, 6; 7, 8, 9;] B = [1;3;1] C = A(B) or C = A(:,B) giving: C…
tarikki
  • 2,166
  • 2
  • 22
  • 32
7
votes
3 answers

transpose for 8 registers of 16-bit elements on SSE2/SSSE3

(I'm a newbie to SSE/asm, apologies if this is obvious or redundant) Is there a better way to transpose 8 SSE registers containing 16-bit values than performing 24 unpck[lh]ps and 8/16+ shuffles and using 8 extra registers? (Note using up to SSSE 3…
alecco
  • 2,914
  • 1
  • 28
  • 37
7
votes
3 answers

How to compare in Matlab two matrices of different dimension and get the frequency of equal rows?

I have matrix A in Matlab of dimension hxk and a matrix B of dimension yxk. I want to construct a vector C of dimension yx1 listing in each row j how many times B(j,:) appears in A.
TEX
  • 2,249
  • 20
  • 43
7
votes
1 answer

How to switch axes (dimensions) in Julia for n-dimensional array

I have an array that I would like to switch the axes order of. It is similar to a transpose except I would like to perform it on arrays with dimensions greater than 2. In Python I would use np.transpose and in Matlab, permute, but I can't seem to…
jtorca
  • 1,531
  • 2
  • 17
  • 31
7
votes
5 answers

A fast way to find nonzero entries by row in a sparse matrix in Python

I am trying to find the indices of nonzero entries by row in a sparse matrix: scipy.sparse.csc_matrix. So far, I am looping over each row in the matrix, and using numpy.nonzero() to each row to get the nonzero column indices. But this method would…
user2498497
  • 693
  • 2
  • 14
  • 22
7
votes
1 answer

Nonnegative matrix factorization in Sklearn

I am applying nonnegative matrix factorization (NMF) on a large matrix. Essentially the NMF method does the following: given an m by n matrix A, NMF decomposes into A = WH, where W is m by d and H is d by n. The ProjectedGradientNMF method is…
user2498497
  • 693
  • 2
  • 14
  • 22
7
votes
2 answers

How do you edit cells in a sparse matrix using scipy?

I'm trying to manipulate some data in a sparse matrix. Once I've created one, how do I add / alter / update values in it? This seems very basic, but I can't find it in the documentation for the sparse matrix classes, or on the web. I think I'm…
Michael L
  • 69
  • 1
  • 6
7
votes
2 answers

matrix operations and component-wise addition using data.table

What is the best way to do component-wise matrix addition if the number of matrices to be summed is not known in advance? More generally, is there a good way to perform matrix (or multi-dimensional array) operations in the context of data.table? I…
Scott
  • 765
  • 4
  • 9
7
votes
1 answer

Python - pandas - Append Series into Blank DataFrame

Say I have two pandas Series in python: import pandas as pd h = pd.Series(['g',4,2,1,1]) g = pd.Series([1,6,5,4,"abc"]) I can create a DataFrame with just h and then append g to it: df = pd.DataFrame([h]) df1 = df.append(g, ignore_index=True) I…
bill999
  • 2,147
  • 8
  • 51
  • 103
7
votes
2 answers

Delete columns of matrix of CSR format in Python

I have a sparse matrix (22000x97482) in csr format and i want to delete some columns (indices of columns numbers are stored in a list)
Asqan
  • 4,319
  • 11
  • 61
  • 100
7
votes
3 answers

how to calculate 2^n modulo 1000000007 , n = 10^9

what is the fastest method to calculate this, i saw some people using matrices and when i searched on the internet, they talked about eigen values and eigen vectors (no idea about this stuff)...there was a question which reduced to a recursive…
manu4rhyme
  • 83
  • 1
  • 4
7
votes
5 answers

bsxfun implementation in matrix multiplication

As always trying to learn more from you, I was hoping I could receive some help with the following code. I need to accomplish the following: 1) I have a vector: x = [1 2 3 4 5 6 7 8 9 10 11 12] 2) and a matrix: A =[11 14 1 5 8 18 …
7
votes
4 answers

Does MATLAB optimize diag(A*B)?

Say I have two very big matrices A (M-by-N) and B (N-by-M). I need the diagonal of A*B. Computing the full A*B requires M*M*N multiplications, while computing the diagonal of it only requires M*N multiplications since there's no need to compute the…
Emil Lundberg
  • 7,268
  • 6
  • 37
  • 53
7
votes
2 answers

Directly creating dummy variable set in a sparse matrix in R

Suppose you have a data frame with a high number of columns(1000 factors, each with 15 levels). You'd like to create a dummy variable data set, but since it would be too sparse, you would like to keep dummies in sparse matrix format. My data set is…
agondiken
  • 863
  • 1
  • 11
  • 17
7
votes
1 answer

Speeding up wilcox.test in R

I am currently trying to implement the Wilcoxon Ranksum test on multiple data sets that I've combined into one large matrix, A, that is 705x17635 (ie I want to run the ranksum test 17,635 times. The only way I've seen how to do this without using…
1 2 3
99
100