Questions tagged [matrix]

16270 questions
1

votes
1

answer
525

Views

Trading in precision for better recall in Keras classification neural net

There's always a tradeoff between precision and recall. I'm dealing with a multi-class problem, where for some classes I have perfect precision but really low recall. Since for my problem false positives are less of an issue than missing true positives, I want reduce precision in favor of increasin...
megashigger
1

votes
1

answer
82

Views

java.lang.IllegalArgumentException: Matrix inner dimensions must agree

Here is my code: package algorithms; import Jama.Matrix; import java.io.File; import java.util.Arrays; public class ThetaGetter { //First column is one, second is price and third is BHK private static double[][] variables = { {1,1130,2}, {1,1100,2}, {1,2055,3}, {1,1047,2}, {1,1927,3}, {1,2667,3}, {1...
Aadit Kolar
1

votes
1

answer
784

Views

Create clusters using correlation matrix in Python

all, I have a correlation matrix of 21 industry sectors. Now I want to split these 21 sectors into 4 or 5 groups, with sectors of similar behaviors grouped together. Can experts shed me some lights on how to do this in Python please? Thanks much in advance!
Jasper C.
1

votes
1

answer
154

Views

How to create a video from images?

I have an algorithm, which after each iteration creates a matrix. After some operations on matrix it is plotted to the user. if I run program 6 times I will get: My goal is to changing image dynamically, like a movie. I have no idea from which side to start. I found some ways of creating video from...
Sergey Vladimirovich
0

votes
0

answer
5

Views

Range minimum query of special binary array

Let A be a binary array (that is, it contains only -1s and 1s), but with a special rule: the true value of A[i] is A[0] + ... + A[i]. Suppose A = {1,1,-1,-1}, than the array of real values should be {1,2,1,0}. How can I retrieve the index of a Range Minimum Query on A without preprocessing the real...
Daniel
1

votes
1

answer
51

Views

Understanding the OpenGL projection matrix

I've been writing a program to display 3d models using OpenGL and until now I've used orthographic projection, but I want to switch to a perspective projection so that as the camera goes toward the model it appears to get larger. I understand that I have to multiply three matrices (model, view, and...
sam
1

votes
2

answer
44

Views

Summing selected elements of a matrix in Python

I have a [n x n] matrix containing values belonging to different groups, and a [1 x n] vector defining to which group each element belongs. (n usually ~1E4, in this example n=4) I want to calculate a matrix obtained by summing together all the elements belonging to the same group. I use np.where() t...
user9998992
1

votes
2

answer
34

Views

Splitting a matrix row based

I have a question with dividing matrixes. I have data of 100 rows and 1024 columns. I want to split that matrix into 2 sub matrices such that 8 rows to matrix 1 and 2 rows to matrix 2 first matrix will be formed r1 r2 r3 r4 r5 r6 r7 r8 r11 r12 r13 ... ... and the second matrix will be formed with r...
Erdem
1

votes
3

answer
31

Views

Given an N-side square matrix, is there a way to find the ring value of a cell without using loops or if conditions?

For instance, imagine you have a 6-side square matrix. These are the cells cartesian indices: (0,0) (0,1) (0,2) (0,3) (0,4) (0,5) (1,0) (1,1) (1,2) (1,3) (1,4) (1,5) (2,0) (2,1) (2,2) (2,3) (2,4) (2,5) (3,0) (3,1) (3,2) (3,3) (3,4) (3,5) (4,0) (4,1) (4,2) (4,3) (4,4) (4,5) (5,0) (5,1) (5,2) (5,3) (5...
Pigna
1

votes
2

answer
20

Views

Turning a presence-absence matrix into a single variable per row in R

I have a presence absence matrix (comprised of 1s and 0s) for each individual ID. It is based on mark recapture data. Each column represents a sampling date. As a data frame, it looks like this (first 3 rows): ID X X.1 X.2 X.3 X.4 X.5 Sex 2014-001 0 0 1 0 1 0 F 2014-002 0 0...
N. J.
1

votes
1

answer
13

Views

Operations in a matrix with its (i,j) values with no for or while loops

I need to write a function in R that receives as inputs the number of rows (r) and the number of columns (c) and generates and output matrix V, where V_(i,j) = r^(abs(i-j)) and r = 2. This function must not have for nor while loops. I just don't know how to access every (i,j) and compute de differen...
Jorge V
1

votes
1

answer
28

Views

How to pretty print a matrix in Octave?

I want to create a pretty printed table from a matrix (or column vector). For Matlab there are several available functions that can do this (such as printmat, array2table, and table), but for Octave I cannot find any. So instead of: >> a = rand(3,2)*10; >> round(a) ans = 2 10 1 3 2 1 I woul...
not2qubit
0

votes
2

answer
14

Views

Manually multiplying two matrices in R

I am using R v 3.0.0 (2013-04-03) and RStudio v 1.1.463 under Win-7 64-bit. In the following source code: # Problem 1 - Matrix powers in R # # R does not have a built-in command for taking matrix powers. # Write a function matrixpower with two arguments mat and k that # will take integer powers k...
user366312
2

votes
2

answer
27

Views

i need to find the first negative number in each column of a matrix

Hello i need to find the position of first negative number for each row vector in a matrix i've tried with match and apply but it ony shows the first z
Matteo Esposito
1

votes
2

answer
2.2k

Views

Generate pixel matrices from characters in string [duplicate]

This question already has an answer here: How to convert from alphabets to pixels 2 answers I'm in the process of writing a library that will print scrolling text across an LED matrix hooked up to a Raspberry Pi. I would like a function that takes a character, height and width and produces a matrix...
Alex
1

votes
2

answer
1.5k

Views

OpenCV mean function crashes with mask created from OpenCV threshold function?

I'm very new to OpenCV, so I guess I'm making some silly mistake. First I'm creating an empty cv::mat matrix, mask, of CV_8U type and filling it with zeros. Then I'm filling the matrix with either 0's or 255's by checking the values in CV_32FC1 type cv::mat matrix croppedDifferenceImage by the use...
the_naive
1

votes
0

answer
9

Views

List of all diagonals in a matrix without using numpy - Python 3

Let's say I got the following matrix: [[5,4,3,2], [8,7,6,5], [4,3,2,0]] I want to create 2 seperate functions that create a list of all diagonals from right to left, and from left to right without using the numpy module! for e.x: [[4], [8,3], [5,7,2], [4,6,0], [3,5], [2]] # these are the right to...
vpam
1

votes
1

answer
1.2k

Views

How can I convert a column vector to the diagonal of a matrix? [duplicate]

This question already has an answer here: How do I convert a n*1 matrix to a n*n diagonal matrix 3 answers I have a column vector that I would like to convert to a diagonal matrix. That is I have the vector v = (1,2,3) and want to turn it into: [1, 0, 0] [0, 2, 0] [0, 0, 3] How can I do this in Exc...
Dan
1

votes
2

answer
420

Views

How to calculate diagonal of a matrix product in Tensorflow?

I have two matrices A and B of shape (M, N) with very large M and small N. I would like to multiply them and then take diagonal of a result: C = tf.matmul(A, B) D = tf.diag_part(C) Unfortunately, this requires of creating of very big (M, M) matrix, which can't fit into memory. But most of this data...
Dims
1

votes
1

answer
10.8k

Views

confusionMatrix for logistic regression in R

I want to calculate two confusion matrix for my logistic regression using my training data and my testing data: logitMod = 0.5, train$LoanStatus_B == 1)) And the the code below works well for my training set. However, when i use the test set: confusionMatrix(table(predict(logitMod, type='response')...
Pumpkin C
1

votes
2

answer
143

Views

Tabulate a combined matrix of coefficients / t-statistics and export in LaTeX

I have many regressions (one per year, over fifteen years) for four outcome variables. I have created two 15x4 matrices: one with the coefficients and one with the t-statistics. I am stuck now that I want to tabulate them in the classic way, each row having the coefficients for each model and under...
Fabio I.
1

votes
3

answer
113

Views

Construct an assignment matrix - Python

I have two lists of element a = [1,2,3,2,3,1,1,1,1,1] b = [3,1,2,1,2,3,3,3,3,3] and I am trying to uniquely match the element from a to b, my expected result is like this: 1: 3 2: 1 3: 2 So I tried to construct an assignment matrix and then use scipy.linear_sum_assignment a = [1,2,3,2,3,1,1,1,1,1] b...
Thanh Nguyen
1

votes
3

answer
70

Views

How to create matrix in python of repeating number?

I want to: Create a vector list from 0 to 4, i.e. [0, 1, 2, 3, 4] and from that Create a matrix containing a 'tiered list' from 0 to 4, 3 times over, once for each dimension. The matrix has 4^3 = 64 rows, so for example T = [0 0 0 0 0 1 0 0 2 0 0 3 0 0 4 0 1 0 0 1 1 0 1 2 0 1 3...
Gabriela
1

votes
1

answer
35

Views

producing a full adjacency matrix from partial information

I have a matrix that contains all the info necessary to construct 5x5 adjacency matrices. Each row represents one matrix: [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 1 1 1 1 1 1 0 1 0 [2,] 0 0 0 1 1 1 1 0 1 0 ... I want to c...
JMQ
1

votes
1

answer
35

Views

Why matrix to raster shows up rotated?

I am trying to convert a matrix (myMat) to raster data (myRas); however, I am not sure why this rotates all of a sudden. This can be easily fixed by 90-degree rotation using t() but, I will be grateful if someone explains why this unwanted rotation happens all the time?! and if there is a way to pre...
Majid
1

votes
3

answer
42

Views

Add number to all negative values in a 4D matrix

I have a matrix DirModel of dimension 2x2x29x1739. I want to add 360 to all negative values in this matrix, but the code I use doesn't keep up the dimensions of this matrix, it makes it into an array: Neg=DirModel
Jellyse
1

votes
3

answer
61

Views

Find no of possible formations of explosive mines in a 2D matrix where some cells contain info about even/odd mines are adjacent to them

I am trying to make game involving 2D grid where given some hints a player can avoid cells containing explosive mines. I have come upon a particular scenario where given certain hints, i want to know how many formations of mines are possible. Let there be a 2D matrix. Each cell may be empty or may c...
iro otaku
1

votes
1

answer
27

Views

Extract square matrices from a Nx2 matrix

I'm working on matlab 2014, I have a matrix 5124x2 and I want to extract all the 2562 square matrices. I found that the unique solution is to use mat2Cell, but it doesn't work for me. I don't really need a cell array at the end, what I want is just all the square matrices %example of data A = rand(5...
amine
1

votes
2

answer
39

Views

How to plot heatmap using 2 matrix in r

I am trying to create a heatmap, but am confused as to how to. Here are the dataframes. Ticker
Zong Hong Tan
1

votes
3

answer
87

Views

How to save a matrix in C++ in a non-linear way

I have to program an optimized multi-thread implementation of the Levenshtein distance problem. It can be computed using dynamic programming with a matrix, the wikipedia page on Levenshtein distance covers that well enough. Now, I can compute diagonal elements concurrently. That is all alright. My...
Jan Kolombo
1

votes
1

answer
33

Views

Margrittr pipe with matrix operations in R

I'm working on some functions that take a matrix as input and provide a matrix as output. Is it possible to use the magrittr pipe with matrices without using the . placeholder? Ideally, I'd like these functions to be piped into each other like a dplyr chain. The issue is that I'm constantly forgetti...
elliot
1

votes
1

answer
74

Views

C - Depth first search in adjacency matrix using recursion

I have a recursion problem I would like to solve using recursion. For example, given this adjacency matrix AdjMat: 0 1 2 3 0 0 1 0 0 1 1 0 1 0 2 0 1 0 1 3 0 0 1 0 Say I would like to look at column 0 and all of its neighbors, and its neighbors' neighbors (distance of 2), and store all of the row in...
leftail
1

votes
1

answer
25

Views

Creating an adjacency matrix from a cell array

I'm going to create an adjacency matrix from a cell array, but faced two main problems: I don't know how to access to cell array's elements; so an adhoc method was used. (and the most important) The code produces an error and the partial result is also a weird one! The cell array is as the following...
dtr43
-2

votes
0

answer
25

Views

Calculate Edit Distance between two strings in Python

I want to compute the edit distance matrix between two strings, at the character level. Here is my function: def editDistance(r, h): ''' This function is to calculate the edit distance of reference sentence and the hypothesis sentence. Main algorithm used is dynamic programming. Attributes: r -> the...
tstseby
1

votes
0

answer
123

Views

Error in colnames

Could anyone help me with some little problem? When I plot the frontier I get the following message: 'Error in colnames
Yury Bobr
1

votes
1

answer
100

Views

Solving an overdetermined sparse linear system produces high error solution

My Code So I have written an algorithm which iteratively solves a sparse overdetermined linear system. That means my code looks like this: construct_A_matrix(); construct_B_matrix(); while(someCondition){ x=solveSystem(A,B) //solve Ax=B. This system is overdetermined //since A has more rows than co...
Iason Manolas
1

votes
0

answer
89

Views

Matrix operations on labeled arrays

I have a system with a linearised set of equations, such that the time-update operation can be performed by a matrix multiplication, y' = Ay, but I would also like to be able to index y using the names of the state variables, e.g. y['vel']. Is there a way to index in this way without losing the abil...
Joe H
1

votes
0

answer
382

Views

How to save the false positive and false negative of confusion matrix in image classification by using SVM?

I have successfully classified two classes of image using support vector machine and correctly calculated the confusion matrix. Here is my codes: import sklearn from sklearn import metrics from sklearn import svm from sklearn.svm import SVC from sklearn.metrics import accuracy_score, f1_score, preci...
Vosco
1

votes
1

answer
67

Views

Solve a redundant system of linear equations in R

I have a noninvertible matrix A and a vector b for which I believe there is a solution x to Ax = b. I would like to find an example of such x. When I try solve(A,b) in R it produces an error because A is singular. Is there any way to make R give me a random solution?
1

votes
1

answer
106

Views

Vector2.Transform(Vector2, Matrix) returns {X:n. def. Y:n. def.}

I'm trying to convert a Vector2 screen position to a world position. I've found this nice method in another Question: public Vector2 ScreenToWorld(Vector2 onScreen) { var matrix = Matrix.Invert(World.Camera.CurrentTransformation); return Vector2.Transform(onScreen, matrix); } But when I use this wit...
globalenemy

View additional questions