matrix

R: Adding two matrices with different dimensions based on columns

扶醉桌前 提交于 2021-02-19 06:22:19
问题 I have 22 matrices having equal number of rows (i.e. 691) and different number of columns (i.e. 22-25). I have to add the values corresponding to same row, same column in each of the matrices resulting in one single matrix of the dimension 691*25. fullanno1 has 691 rows & 25 columns: >colnames(fullanno1) [1] "coding-notMod3" "coding-synonymous" "coding-synonymous-near-splice" [4] "intergenic" "intron" "missense" [7] "missense-near-splice" "near-gene-3" "near-gene-5" [10] "splice-3" "splice-5"

Create weighted igraph Graph from numpy summetric 2D array as adjacency matrix

陌路散爱 提交于 2021-02-19 05:36:12
问题 I am having a numpy 2D array, with the values representing the weights of edges between nodes. The matrix is symmetric, and I take the diagonal to be zero. I don't find an example of how to convert this matrix into igraph Graph object. I've tried the following approach, but it doesn't work: import numpy as np import igraph def symmetrize(a): return a + a.T - 2*np.diag(a.diagonal()) A = symmetrize(np.random.random((100,100))) G = igraph.Graph.Adjacency(A.tolist()) 回答1: Use Graph.Weighted

sscanf usage on matrix of unknown size?

此生再无相见时 提交于 2021-02-19 05:26:16
问题 So, I have a file that contains a matrix of NxM size. For example: P2 3 3 1 1 0 0 0 1 0 0 0 1 The 'P2' is just an useless indicator, the first '3' indicates how many columns are and the second '3' indicates how many lines, '1' indicates the maximum value among the matrix's numbers. This matrix was stored in a data structure like this: typedef struct { int c; // columns int l; // lines unsigned char max; // max value unsigned char** data // variable to store matrix's numbers } Matrix; To store

rotate Z axis on 2d image's matrix in shader

ぐ巨炮叔叔 提交于 2021-02-19 04:41:28
问题 I'm trying to rotate a 2d image's matrix inside the vertex shader. I want the 2d image to rotate around what I think would be the z axis. However The closes I've ever gotten is: Here is my matrix inside my shader that I apply translation and scaling on: mat4 worldPosTrans = mat4(vec4(scale.x * cos(rotateZ), 0, 0, 0), vec4(0, scale.y, 0, 0), vec4(0, 0, scale.z, 0), vec4(translation, 1)); This is a slightly changed version from something that was supposed to rotate everything: mat4

Finding all combinations of multiple variables summing to 1

混江龙づ霸主 提交于 2021-02-19 04:09:13
问题 I am trying to solve the equation x1 + x2 + x3 + .... + xn = 1 where the values of all xi are restricted to [0, 0.1, 0.2, ..., 0.9, 1] . Currently, I am solving the problem by first generating an n-dimensional array mat , where at each element location the value is the sum of the axis values, which vary in axisValues = 0:0.1:1 : mat(i,j,k,...,q) = axisValues(i) + axisValues(j) + ... + axisValues(q). Then I search for all entries of the resulting array that are equal to one. The code (shown

Finding all combinations of multiple variables summing to 1

感情迁移 提交于 2021-02-19 04:05:14
问题 I am trying to solve the equation x1 + x2 + x3 + .... + xn = 1 where the values of all xi are restricted to [0, 0.1, 0.2, ..., 0.9, 1] . Currently, I am solving the problem by first generating an n-dimensional array mat , where at each element location the value is the sum of the axis values, which vary in axisValues = 0:0.1:1 : mat(i,j,k,...,q) = axisValues(i) + axisValues(j) + ... + axisValues(q). Then I search for all entries of the resulting array that are equal to one. The code (shown

Converting a Number Matrix to a Color Matrix in R

独自空忆成欢 提交于 2021-02-18 20:51:15
问题 I have the following 4x4 number matrix containing the numbers 0-4: 0 1 0 3 3 2 1 4 4 1 0 2 3 3 0 1 I would like to understand how to convert number matrices into a color matrices using chosen colors and specific square dimensions (length x width) using R. To be clear, I'm defining color matrix as a figure using colored squares to represent specific values in a matrix orientation. An example 4x4 from another program follows: I would have to assign color codes to the numbers, for example: 0 =

Transforming a table in a 3D array in R

余生长醉 提交于 2021-02-18 12:34:07
问题 I have a matrix: R> pippo.m [,1] [,2] [,3] [,4] [1,] 1 2 3 4 [2,] 5 6 7 8 [3,] 9 10 11 12 [4,] 13 14 15 16 [5,] 17 18 19 20 [6,] 21 22 23 24 and I would like to transform this matrix in a 3D array with dim=(2,4,3). Passing through the transponse of pippo.m I am able to obtain a similar result but with columns and rows rotated. > pippo.t <- t(pippo.m) > pippo.vec <- as.vector(pippo.t) > pippo.arr <- array(pippo.vec,dim=c(4,2,3),dimnames=NULL) > pippo.arr , , 1 [,1] [,2] [1,] 1 5 [2,] 2 6 [3,]

combine two looping structures to obtain a matrix output

怎甘沉沦 提交于 2021-02-18 08:38:49
问题 I'm using two closely related formulas in R. I was wondering if it might be possible to combine B1 and B2 to get my desired matrix output shown below? z <- "group y1 y2 1 1 2 3 2 1 3 4 3 1 5 4 4 1 2 5 5 2 4 8 6 2 5 6 7 2 6 7 8 3 7 6 9 3 8 7 10 3 10 8 11 3 9 5 12 3 7 6" dat <- read.table(text = z, header = T) (B1 = Reduce("+", group_split(dat, group, .keep = FALSE) %>% map(~ nrow(.)*(colMeans(.)-colMeans(dat[-1]))^2))) # y1 y2 #61.86667 19.05000 (B2 = Reduce("+",group_split(dat, group, .keep =

How to concatenate two matrices in Python?

我与影子孤独终老i 提交于 2021-02-18 05:33:50
问题 I have two csr_matrix , uniFeature and biFeature . I want a new matrix Feature = [uniFeature, biFeature] . But if I directly concatenate them this way, there's an error that says the matrix Feature is a list. How can I achieve the matrix concatenation and still get the same type of matrix, i.e. a csr_matrix ? And it doesn't work if I do this after the concatenation: Feature = csr_matrix(Feature) It gives the error: Traceback (most recent call last): File "yelpfilter.py", line 91, in <module>