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.

30,867 questions
16 views

Python Matrix multiplication for making grid

Is there any simple way/command in Python to make two (or three) matrix multiplications to get Product Kernel, e.g. expanding for grid ? I mean points should be evaluated for each combination of grid. ...
38 views

Function that creates matrix 5x5 + function that creates HTML view of the matrix

I got the following task: "Implement a function numberMatrix() (using JS) which creates HTML view of matrix 5x5 like mentioned below: 1 3 3 3 3 2 1 3 3 3 2 2 1 3 3 2 2 2 1 3 2 2 2 2 1 ! Note: It ...
14 views

Insert array elements into matrix

How can the elements from (take only range 3 to 8) a = np.array([1,2,3,4,5,6,7,8,9]) go to A = np.array([[0,0,0], [0,0,0]]) Ideal output would be: A = ([[3,4,5], [6,7,8]])
17 views

including rowname when using sapply

I am trying to apply a function to a dataframe using sapply. The function is the Erlang C calculation which I found from one of the sites that I came across while researching. What I am having ...
19 views

How to apply classification machine learning methods on a dataset in matrice format? [on hold]

I have a dataset related to 27 different subjects. For each subject, I have a 2D matrix of 100*32. I would like to do a binary classification, i.e. each subject (27 subjects) has a label of 0 or 1. ...
11 views

Efficiently reshuffling a long matrix into one consisting of column bound subblocks (of the original) in R

"I have a very long matrix, measuring 30^5 x 3 entries. I basically consists of subblocks of 10.000 30 x 3 matrices, stacked on top of one another. I want to afficiently "cbind" them, next to one ...
29 views

how to fix Matrix dimensions must agree

I am trying to plot Z0 in term of t I get this error Matrix dimensions must agree. I know that ‘T’ is a scalar, and ‘X’ and ‘Y’ are (51x26) matrices, and ‘t’ is a (1x501) vector.It is not possible to ...
22 views

Matrix vs function for matrix operations

Since I couldn't find anything about this subject, I decided to ask this question here. I am completely beginner and this question might be ridiculous. Suppose we have A(NxN) matrix and a column ...
29 views

Apply a function to every column of a matrix

What is the most efficient and concise way to apply a function to each column (or row) of a matrix? Suppose I have a matrix, and to simplify, a minimal working matrix: julia> mtx 4×2 Array{...
19 views

Calculating adjusted p-values from matrix while retaining matrix dimensions in R

I calculated between- and within-individual correlations using the statsBy function from the psych package as follows: statsBy(df[,c(1,10,12,13,14,17,20,24:25)], "group", na.rm = TRUE) I then ...
26 views

How to make dot.product of 2D and 3D matrices (taking it for each dimension separately)

I need to calculate dot product of two matrices. Probably tensordot would do the job, however I am struggling to figure out exact solution. The simple option res = np.dot(x, fullkernel[:, :-1]....
19 views

Simplest way of getting the neighbors of a cell in a grid (or matrix)

I'm often facing this situation where I need to find the existing neighbors and I am still not satisfied with the solution I use. In the event of a squared grid (or a dim2 matrix), like: [[ 1, 2, 3, ...
53 views

Creating a Square Matrix

Hello can someone please help me, I'm trying to do a square matrix in java with this format: 1 | 6 | 7 | 12 2 | 5 | 8 | 11 3 | 4 | 9 | 10 What I want is that the code generates a table with the ...
22 views

Uniqe ID in list of indexed 2D/3D Image masks (or 2D/3D matrix) in R

I want to make a "global" ID of 2D/3D nuclear masks across a list of images. When i segment my cells they are numbered from 1:numberOfCellsInEachImage. but I would like to have an uniqe Id for each ...
45 views

Efficient way of computing quadratic forms for outer product matrices

I'm currently computing a quadratic form by taking a known vector and using the element wise multiplication of two outer products as the input matrix. To be specific, my code looks something like this ...
22 views

Why android.Matrix.setRotateM returns a matrix whose rotation direction is the opposite of the expected rotation matrix?

For example, if I give the following parameters: float[] rotateMatrix = identityMatrix.clone(); Matrix.setRotateM(rotateMatrix, 0, 90, 0, 0, 1); I expect a matrix which rotates 90 degrees counter ...
15 views

Cluster a Binary Matrix

I'm looking to create clusters around all 1s and 0s. Similar to Mindsweeper, I want to basically "draw a circle" around all 1s, and create a border where 0s exist. I have tried using hclust() and ...
25 views

Looking for a good Computer Vision framework for Android Studio

I am looking a good computer vision API or android studio framework class, like OpenCV (I need other one, develop by google). What I need is read mobile camera data, in matrix representation. ...
16 views

Power BI : Matrix Get the difference of two columns

I am trying to figure out how to get the difference of two columns within a row in Matrix everything that was available in the community has been hardcoding the values of the column label. I would ...
31 views

matrix index matching for large raster data

I have a large raster data (X) with a dimension of 32251*51333. The values of X are repetitions of another array (Y), which has a size of 3*10^6. Now I want to change the values of X by matching it ...
16 views

Fastest way to save coordinate matrix as image matrix in R

I have lots of points (coordinates) and I wish to store it as image matrix dx x dy such as missing values mark as 0, otherwise put 1. sample: > s [,1] [,2] [1,] 452937.5 359878 [2,] ...
41 views

Make a matrix with NA values numeric

I haven't got the newest question but already read and tried everything I could find and none worked. My goal is to make a heatmap from a data with a lot of NA values. I have a 177x11 xls table, my ...
17 views

Zoom to point with a matrice C#

I would like to make a simple zoom to point, using matrices. I've tried several ways, like scaling the matrice with a zoomfactor, but it only zooms to the upper left corner (0,0). How do i achieve to ...
36 views

Svg scaling rotated elements on mouse drag

I'm playing around with svgs and matrixes for a project I'd like to work on and I'm trying to implement a free transform with vanilla javascript. As of now I am able to do all transformations with ...
17 views

Convert a data frame to matrix using indexing [duplicate]

I have a data frame like below: df<- read.table(text = "A B C a1 abcd 1 b2 abcd -1 c2 efgh 1 v4 uh 1 g5 vghvb 0 ",header=T) and I want to convert to a matrix like this: ...
55 views

I have a large gzipped file (5000 columns × 1M lines) consisting of 0's and 1's: 0 1 1 0 0 0 1 1 1....(×5000) 0 0 0 1 0 1 1 0 0 ....(×1M) I want to transpose it, but using numpy or other methods ...
58 views

Reshape matrix by rows

I have a matrix with size 18000 x 54. I would like to reshape it as a matrix with size 54000 x 18, in which each row of my initial matrix becomes a matrix which has 3 rows. Let's take an example. I ...
29 views

How to speed up writing to a matrix in a reference class in R

Here is a piece of R code that writes to each element of a matrix in a reference class. It runs incredibly slowly, and I’m wondering if I’ve missed a simple trick that will speed this up. nx = 2000 ...
14 views

How to solve the SVD problem with the constraint that the subspaces spanned the first K left and right vectors are the same?

I'm trying to solve the problem of finding the K leading 'singular vectors' of a matrix. Different from the standard SVD problem, I need the subspace spanned by the left and right 'singular vectors' ...
57 views

Multiplying Matrices of Vectors using Dot Product

I am given two 2D matrices where each of the cells is a vector with three elements. What I'm looking to do is use 2D matrix multiplication where when any of the cells are multiplied together, it ...
26 views

How to order a matrix by the numeric or alphabetic values of the column vectors in R?

The title with the following example should be self-explanatory: m = unique(replicate(5, sample(1:5, 5, rep=F)), MARGIN = 2) m [,1] [,2] [,3] [,4] [,5] [1,] 1 5 1 4 3 [2,] 5 ...
8 views

Any way of getting the canvas transformation matrix or at least the translation values?

I'm drawing in another view's canvas but I'm getting a translation. How to calculate or get the canvas translation if the method is deprecated? I'm drawing on the screen with a finger, but using ...
45 views

How to plot data as 2x 2 matrix

I have a short table includind three columns, two text columns (column 1 and column 2) and one numerical column. I would like to have a matrix / scatter plot (x and y as column 1 and column 2) and ...
37 views

How much space needed for a R matrix cell with 0 value? And how to deal with big matrix calculation

I want to calculate the correlation for a matrix, but stopped by program since the memory is not able to fit. M = matrix(0, length(user), length(mat)) when I run this line,I got a message ...
40 views

Correlation matrix of many variables (r and p-value)

I'm creating a correlation matrix for a very large database which includes 85 variables. My data contains missing values. So far I analyzed the whole DB, would you suggest to break it down in smaller ...
24 views

Remove negative part of the frequency spectrum after FFT operation

I have a matrix where I have performed an FFT operation, and I can view it using the imagesc function. However, I am seeing the negative spectrum as well, as shown in the figure below. The diagram I ...
41 views

MATLAB to convert xy plot to xyz array

I have a series of curves plotted in x vs. y format in MATLAB. I want to describe the shape they create at their intersection in an xyz format (a 2D array). There is no simple function in MATLAB to ...
21 views

Write a function given a zero-indexed matrix A consisting of N rows and M columns of integers, returns the number of equilibrium points of matrix A

Hey guys I am doing a question where I have to find a point in a Matrix A of N x M rows such that the sum of rows above the point is equal to the sum of row Consider this example /** * A = 2 ...
7 views

Corrplot.mixed plot (number and square together)

Trying to put together the coefficient values (lower corner) and significance (upper corner) Try using corrplot.mixed but doing something wrong library(corrplot) library(Hmisc) mydata <- read.csv(...
45 views

Segmentation fault in creating a sparse matrix(Gallagers parity check matrix) [on hold]

I'm trying to implement the following: A matrix with binary entries alone, such that it has a fixed number of 1's in all the columns(wc) and also fixed number(wr) of 1's in all the rows. note: wr != ...
36 views

What is the rule behind the way singleton dimensions are squeezed in a submatrix?

It appears to me that MATLAB squeezes the singleton dimensions on the right-hand side of the last non-singleton dimension, with the restriction that a matrix must be at least two dimensional. ...
59 views

Getting weird output for dynamic allocation of the 2d array. How can I resolve the issue?

I want to create a dynamic 2d array and want to perform the operation on it. However, when I print the matrix, the first column shows different numbers, and don't know where is it coming from? I ...
27 views

How to reduce dimension of gene expression matrix by calculating correlation coefficients?

I am in interested in finding Pearson correlation coefficients between a list of genes. Basically, I have Affymetrix gene level expression matrix (genes in the rows and sample ID on the columns), and ...
45 views

How do I rotate a matrix 90 degrees counterclockwise in java?

I'm trying to go over the problems in the Cracking the Coding Interview book. One of the questions asks me to rotate a matrix 90 degrees clockwise. Now, while trying to solidify my understanding of ...
23 views

What is the Logic behind this matrix multiplication?

I am trying to multiply these 1 dimensional matrices( or vectors) with each other as follows : a = np.array([1,2,3]).reshape(1,3) b = np.array([4,5,6]).reshape(1,3) c = np.dot(a,b) print(c) ...
52 views

Indexing multiple array/ matrix elements similar to matlab “var[1:10]” in C

for my calculations i need to index into an array. I am used to MATLAB where you can index in a way such as var[1:10] // extracts the first through to the 10th element of "var" I am trying to find ...
15 views

How to find the reverse code of zigzag scanning of matrix using matlab?

I have an image and I want to encrypt it using zigzag scanning. I have a problem in the decryption because I need the code of the inverse zigzag scanning so I can restore the original image of 2 ...
57 views

How can I modify a 2d matrix so that predefined sums in both dimensions are satisfied?

I'm working on optimizing production of a number of related widgets over a number of weeks. The total quantity of each widget, and the total quantity of widgets produced each week is fixed. By ... 