matrix

Unpivot an Excel matrix/pivot-table?

∥☆過路亽.° 提交于 2020-01-27 08:40:28
问题 Is there a quick way to "unpivot" an Excel matrix/pivot-table (in Excel or elsewhere), without writing macros or other code ? Again, I can write code (C# or VBA or whatever) that does that myselfs. I want to know if it is possible to do it without code, quickly ? E.g. I need to convert this permission matrix (given as Excel-table/matrix) into this half-normalized table (so I can insert it into a SQL database): e.g. in SQL I could do it like this: CREATE TABLE dbo.T_DocumentMatrix ( [Function]

48. 旋转图像(java)

喜欢而已 提交于 2020-01-26 23:18:41
给定一个 n × n 的二维矩阵表示一个图像。 将图像顺时针旋转 90 度。 说明: 你必须在原地旋转图像,这意味着你需要直接修改输入的二维矩阵。请不要使用另一个矩阵来旋转图像。 示例 1: 给定 matrix = [ [1,2,3], [4,5,6], [7,8,9] ], 原地旋转输入矩阵,使其变为: [ [7,4,1], [8,5,2], [9,6,3] ] 示例 2: 给定 matrix = [ [ 5, 1, 9,11], [ 2, 4, 8,10], [13, 3, 6, 7], [15,14,12,16] ], 原地旋转输入矩阵,使其变为: [ [15,13, 2, 5], [14, 3, 4, 1], [12, 6, 8, 9], [16, 7,10,11] ] 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/rotate-image 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 class Solution { public void rotate ( int [ ] [ ] matrix ) { int n = matrix . length ; for ( int i = 0 ; i < n / 2 ; i ++ ) { for ( int j = i ; j < n - i -

[Leetcode Weekly Contest]173

白昼怎懂夜的黑 提交于 2020-01-26 20:12:54
链接: LeetCode [Leetcode]5319.删除回文子序列 给你一个字符串 s,它仅由字母 'a' 和 'b' 组成。每一次删除操作都可以从 s 中删除一个回文 子序列。返回删除给定字符串中所有字符(字符串为空)的最小删除次数。 注意这里,「子序列」定义:如果一个字符串可以通过删除原字符串某些字符而不改变原字符顺序得到,那么这个字符串就是原字符串的一个子序列。 「回文」定义:如果一个字符串向后和向前读是一致的,那么这个字符串就是一个回文。 这道题关键在于“审题”,当发现字符串仅有字母 'a' 和 'b' 组成,那么我们联想到,删除给定字符串中所有字符(字符串为空)的最小删除次数只有三种情况: 0种,即字符串为空 1种,即字符串本身为回文 2种,即其他情况。因为当字符串仅有字母 'a' 和 'b' 组成,则我们可以将所有包含a的子序列提取出来删除,再将所有b的子序列删除,此时只需要两次就实现了删除所有字符。 class Solution: def removePalindromeSub(self, s: str) -> int: if not s: return 0 if s == s[::-1]: return 1 return 2 [Leetcode]5320.餐厅过滤器 给一个餐馆信息数组 restaurants,其中 \(restaurants[i] = [idi

Find all solutions of row reduced echelon matrix in pure python

杀马特。学长 韩版系。学妹 提交于 2020-01-26 02:07:30
问题 I have toggle = [[1, 1, 1, 1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] puzzle = [0, 0, 0, 0, 1, 0, 0, 0, 0] toggle is a matrix I already transformed to [row echelon form] with Gaussian elimination. This is in GF(2) space, which means that -1 = 1 and 1 + 1 = 0 . I already have a working

Find all solutions of row reduced echelon matrix in pure python

妖精的绣舞 提交于 2020-01-26 02:07:22
问题 I have toggle = [[1, 1, 1, 1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 1, 0], [0, 0, 0, 1, 1, 0, 1, 1, 0], [0, 0, 0, 0, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]] puzzle = [0, 0, 0, 0, 1, 0, 0, 0, 0] toggle is a matrix I already transformed to [row echelon form] with Gaussian elimination. This is in GF(2) space, which means that -1 = 1 and 1 + 1 = 0 . I already have a working

How do I get (LaTeX math) typeset matrix with borders in HTML output from *.Rmd?

自闭症网瘾萝莉.ら 提交于 2020-01-25 23:41:57
问题 The following rmarkdown works fine when compiling to PDF (via LaTeX), but not when compiling to HTML (via Markdown). PDF (via LaTeX) --- title: "test" author: "Maximilian Held" output: pdf_document documentclass: memoir --- (@matrix-test2) $$ \bordermatrix{ ~ & Petra & Ingrid \cr Petra & 1 & 0 \cr Ingrid & 0 & 1 \cr } $$ HTML (via Markdown) --- title: "test" author: "Maximilian Held" output: html_document documentclass: memoir --- (@matrix-test2) $$ \bordermatrix{ ~ & Petra & Ingrid \cr Petra

Transform attribute vector into a matrix with differences of elements

*爱你&永不变心* 提交于 2020-01-25 23:39:07
问题 Similarly to this previous post I need to transfrom an attribute vector into a matrix. This time with differences between pairs of elements using R. For example I have a vector which reports the age of N people (from 18 to 90 years). I need to convert this vector into a NxN matrix named A (with people names on rows and columns), where each cell Aij has the value of |age_i-age_j|, representing the absolute difference in age between the two people i and j. Here is an example with 3 persons,

How to show a similarity of two columns in percentage using R?

跟風遠走 提交于 2020-01-25 22:28:11
问题 I have a simple question which I stock in it! I have two data.frames and I want to compare them and show their similarity in percentage but I do not know how! Here is a simple example: a <- as.matrix(rbinom(10,1,1/2)) b <- as.matrix(rbinom(10,1,1/2)) > a [,1] [1,] 1 [2,] 0 [3,] 1 [4,] 0 [5,] 1 [6,] 0 [7,] 1 [8,] 1 [9,] 1 [10,] 0 > b [,1] [1,] 1 [2,] 0 [3,] 1 [4,] 1 [5,] 0 [6,] 0 [7,] 0 [8,] 0 [9,] 1 [10,] 0 I know that table shows the differences/similarities > table(a,b) b a 0 1 0 3 1 1 3 3

Imputation with column medians in R

别说谁变了你拦得住时间么 提交于 2020-01-25 21:40:17
问题 If I have a vector, for example vec <- c(3,4,5,NA) I can replace the NA with the median value of the other values in the vector with the following code: vec[which(is.na(vec))] <- median(vec, na.rm = T) However, if I have a matrix containing NAs, applying this same code across all columns of the matrix doesn't give me back a matrix, just returning the medians of each matrix column. mat <- matrix(c(1,NA,3,5,6,7,NA,3,4,NA,2,8), ncol = 3) apply(mat, 2, function(x) x[which(is.na(x))] <- median(x,

Imputation with column medians in R

亡梦爱人 提交于 2020-01-25 21:40:12
问题 If I have a vector, for example vec <- c(3,4,5,NA) I can replace the NA with the median value of the other values in the vector with the following code: vec[which(is.na(vec))] <- median(vec, na.rm = T) However, if I have a matrix containing NAs, applying this same code across all columns of the matrix doesn't give me back a matrix, just returning the medians of each matrix column. mat <- matrix(c(1,NA,3,5,6,7,NA,3,4,NA,2,8), ncol = 3) apply(mat, 2, function(x) x[which(is.na(x))] <- median(x,