matrix

How to convert a matrix into column array with PANDAS / Python

风格不统一 提交于 2020-07-08 19:20:47
问题 I need to convert a matriz (below) into a 3 column list. I currently have a DataFrame as this: A B C ... a 1 3 4 ... b 4 0 6 ... c 9 8 0 ... and I need to get a results as this: Source Target Weight a A 1 a B 3 a C 4 b A 4 b C 6 c A 9 c B 8 I've been trying to use pandas.pivot_table function, but I can't get the result needed. 回答1: you can use DataFrame.stack() method: In [335]: df.stack().reset_index().rename(columns={'level_0':'Source','level_1':'Target', 0:'Weight'}) Out[335]: Source

Error when using rot90 on 3D numpy array with 3 arguments

六月ゝ 毕业季﹏ 提交于 2020-07-07 19:31:50
问题 Python 2.7.10; Numpy 1.8.1 While going through the examples on matrix rotation here I keep getting an error. The code: m = np.arange(8).reshape((2,2,2)) np.rot90(m, 1, (1,2)) The error: TypeError: rot90() takes at most 2 arguments (3 given) I tried copy and pasting, and typing out, the code, but no joy. I understand the text of the error, but not the why, especially since it is code direct from the SciPy site. What is the issue? 回答1: Unfortunately, I think the New in version 1.12.0. has been

Error when using rot90 on 3D numpy array with 3 arguments

牧云@^-^@ 提交于 2020-07-07 19:28:11
问题 Python 2.7.10; Numpy 1.8.1 While going through the examples on matrix rotation here I keep getting an error. The code: m = np.arange(8).reshape((2,2,2)) np.rot90(m, 1, (1,2)) The error: TypeError: rot90() takes at most 2 arguments (3 given) I tried copy and pasting, and typing out, the code, but no joy. I understand the text of the error, but not the why, especially since it is code direct from the SciPy site. What is the issue? 回答1: Unfortunately, I think the New in version 1.12.0. has been

Finding The Max of sum of elements in matrix in distinct rows and columns

三世轮回 提交于 2020-07-06 11:21:18
问题 I have a nxm matrix and I need to find the maximum of sum of its values in distinct rows and columns. For example considering the following Matrix: m1 m2 m3 n1 1 2 3 n2 4 5 6 n3 7 8 9 n4 10 11 12 The max will be 12+8+4 = 24 Note that finding the max and eliminating all values belonging to that column or row is not a good solution as it doesn't work for all cases. The exception for above will be the following: m1 m2 n1 17 1 n2 18 15 If you find 18 and remove 17 and 15, the sum will be 18+1 =

Finding The Max of sum of elements in matrix in distinct rows and columns

百般思念 提交于 2020-07-06 11:18:21
问题 I have a nxm matrix and I need to find the maximum of sum of its values in distinct rows and columns. For example considering the following Matrix: m1 m2 m3 n1 1 2 3 n2 4 5 6 n3 7 8 9 n4 10 11 12 The max will be 12+8+4 = 24 Note that finding the max and eliminating all values belonging to that column or row is not a good solution as it doesn't work for all cases. The exception for above will be the following: m1 m2 n1 17 1 n2 18 15 If you find 18 and remove 17 and 15, the sum will be 18+1 =

How to use corrplot with simple matrices

你说的曾经没有我的故事 提交于 2020-07-05 07:56:10
问题 I have a simple 8 by 8 matrix M <- matrix(rnorm(64), nrow=8, ncol=8) How should I transform it to plot it with library(corrplot) ? Without transformation the error is: corrplot.mixed(M) Error in corrplot(corr, type = "upper", method = upper, diag = TRUE, tl.pos = tl.pos, : The matrix is not in [-1, 1]! which I guess would assume that the matrix should be [-1, 1]? 回答1: Just indicate that it is not a correlation matrix: library(corrplot) corrplot(M, is.corr = FALSE, method = "square") 来源: https

Eigen: convert Matrix3d rotation to Quaternion

本小妞迷上赌 提交于 2020-07-03 05:49:20
问题 I'm trying to convert a Matrix3d rotation to a Quaternion<double> , but I got only weird compiler errors so far. The code I'm using is: Quaternion<double> getQuaternionFromRotationMatrix(const Matrix3d& mat) { AngleAxisd aa; aa = mat; Quaternion<double> q = aa;// conversion error return q; } And the compiler errors: path/src/Utils.cpp: In function ‘Eigen::Quaternion<double> Utils::getQuaternionFromRotationMatrix(const Matrix3d&)’: path/src/Utils.cpp:55:26: error: conversion from ‘Eigen:

Eigen: convert Matrix3d rotation to Quaternion

混江龙づ霸主 提交于 2020-07-03 05:46:25
问题 I'm trying to convert a Matrix3d rotation to a Quaternion<double> , but I got only weird compiler errors so far. The code I'm using is: Quaternion<double> getQuaternionFromRotationMatrix(const Matrix3d& mat) { AngleAxisd aa; aa = mat; Quaternion<double> q = aa;// conversion error return q; } And the compiler errors: path/src/Utils.cpp: In function ‘Eigen::Quaternion<double> Utils::getQuaternionFromRotationMatrix(const Matrix3d&)’: path/src/Utils.cpp:55:26: error: conversion from ‘Eigen:

BLAS LDB using DGEMM

亡梦爱人 提交于 2020-06-29 05:54:19
问题 I want to multiply matrices by D*W', where W' is a transposed version of W. While I'll use DGEMM I'l figured out with the help of @IanBush that the LDB in this case should be number of rows of matrix W instead of number of columns. The code for this case is Call dgemm('n', 't', N1, M1, N1, 1.0_wp, D, N1, W, M1, 0.0_wp, c, n1) where n1 and m1 are dimensions of my matrices Dimensions of the matrices: W = M1*N1 D = N1*N1 As in official documentation it says LDB is INTEGER On entry, LDB specifies

MySQL query to create a pivot table by joining 4 different table

核能气质少年 提交于 2020-06-29 03:45:14
问题 I have 4 mySQL tables namely Exams, Marks, Student and Subject. Sql with data is provided below. I need the output like below screenshot. Marks is calculated from all Marks added together for the particular subject and student pair with their proper Weightage in Percentage (Exams with 0 Weightage are ignored) I tried using the below query but the result didn't gave the cumulative marks so need help. SET @sql = NULL; SELECT GROUP_CONCAT(DISTINCT CONCAT('MAX(IF(sj.SubjectId = ''', SubjectId,'''