matrix

How to show different groups in same matrix where no parent or child relationship

元气小坏坏 提交于 2020-06-29 03:34:51
问题 I am tasked with reproducing a spreadsheet in an SSRS report to save hours of Excel spreadsheet work. I have done all the calculations and got them into a single dataset however I am not able to work out how to display in the same table/matrix. My spreadsheet looks like this: Column B is a text column used to describe what the figures in each group are showing. Col C is 'Region' grouping. I have got this far with my matrix - grouping by region and month. This gives me rows 3 to 8 incl of the

3D numpy array into block diagonal matrix

被刻印的时光 ゝ 提交于 2020-06-27 09:56:11
问题 I am looking for a way to convert a nXaXb numpy array into a block diagonal matrix. I have already came across scipy.linalg.block_diag, the down side of which (for my case) is it requires each blocks of the matrix to be given separately. However, this is challenging when n is very high, so to make things more clear lets say I have a import numpy as np a = np.random.rand(3,2,2) array([[[ 0.33599705, 0.92803544], [ 0.6087729 , 0.8557143 ]], [[ 0.81496749, 0.15694689], [ 0.87476697, 0.67761456]]

Factorial of a matrix elementwise with Numpy

拥有回忆 提交于 2020-06-27 07:36:32
问题 I'd like to know how to calculate the factorial of a matrix elementwise. For example, import numpy as np mat = np.array([[1,2,3],[2,3,4]]) np.the_function_i_want(mat) would give a matrix mat2 such that mat2[i,j] = mat[i,j]! . I've tried something like np.fromfunction(lambda i,j: np.math.factorial(mat[i,j])) but it passes the entire matrix as argument for np.math.factorial . I've also tried to use scipy.vectorize but for matrices larger than 10x10 I get an error. This is the code I wrote:

How to find the rotation matrix between two coordinate systems?

爷,独闯天下 提交于 2020-06-24 01:56:10
问题 There are two coordinate systems. We know the 3D coordinates of the origin and the 3D vectors of the axes of the second coordinate system with respect to the first coordinates system. Then how can we find the rotation matrix that transforms the first coordinate system into the second coordinate system? 回答1: The problem described can be solved as follows. Let M = m_11 m_12 m_13 m_21 m_22 m_23 m_31 m_32 m_33 denote the desired rotation matrix. We require 1 0 0 * M + t = x_x x_y x_z 0 1 0 y_x y

sort matrix up to nth column c++

淺唱寂寞╮ 提交于 2020-06-17 09:36:10
问题 If I have a matrix like this: 4 5 3 6 8 7 9 5 4 2 1 3 and I want only to sort only the first two rows such that I get: 3 4 5 6 7 8 9 5 4 2 1 3 How can I achieve that using C++14? 回答1: C++ STL provides a function sort that sorts a vector or array. The average of a sort complexity is N*log2 (N) Syntax: sort(first, last); Here, first – is the index (pointer) of the first element in the range to be sorted. last – is the index (pointer) of the last element in the range to be sorted. Example: For

How to scale a NumericMatrix in-place with Rcpp?

为君一笑 提交于 2020-06-16 05:13:38
问题 This is what I'm doing now library(Rcpp) A <- diag(c(1.0, 2.0, 3.0)) rownames(A) <- c('X', 'Y', 'Z') colnames(A) <- c('A', 'B', 'C') cppFunction(' void scaleMatrix(NumericMatrix& A, double x) { A = A * x; }') Unfortunately It doesn't work :( > A A B C X 1 0 0 Y 0 2 0 Z 0 0 3 > scaleMatrix(A, 2) > A A B C X 1 0 0 Y 0 2 0 Z 0 0 3 I learned from Rcpp FAQ, Question 5.1 that Rcpp should be able to change the object I passed by value. Stealing an example from Dirk's answer to my previous question:

How to scale a NumericMatrix in-place with Rcpp?

蓝咒 提交于 2020-06-16 05:13:33
问题 This is what I'm doing now library(Rcpp) A <- diag(c(1.0, 2.0, 3.0)) rownames(A) <- c('X', 'Y', 'Z') colnames(A) <- c('A', 'B', 'C') cppFunction(' void scaleMatrix(NumericMatrix& A, double x) { A = A * x; }') Unfortunately It doesn't work :( > A A B C X 1 0 0 Y 0 2 0 Z 0 0 3 > scaleMatrix(A, 2) > A A B C X 1 0 0 Y 0 2 0 Z 0 0 3 I learned from Rcpp FAQ, Question 5.1 that Rcpp should be able to change the object I passed by value. Stealing an example from Dirk's answer to my previous question:

How can I construct a matrix given a generator for this cyclic group?

倾然丶 夕夏残阳落幕 提交于 2020-06-16 04:12:46
问题 Let F[q^p] be a finite cyclic set of polynomials, where q is a prime number and p is an integer greater than 0. Each element in F[q^p] will be a polynomial up to degree (p-1) under (mod q). Ex: F[2^2]={0,1,x,1+x} Ex: F[3^4]={0,1,2,0+x,1+x,2+x,0+x^2,1+x^2,2+x^2,x+x^2,1+x+x^2,2+x+x^2,2x+x^2,1+2x+x^2,2+2x+x^2,0+2x^2,1+2x^2,2+2x^2,x+2x^2,1+x+2x^2,2+x+2x^2,2x+2x^2,1+2x+2x^2,2+2x+2x^2,...,2+2x+2x^2+2x^3} Thus, there will be q^p elements in F[q,p]. Assume that we have a generator theta, where theta

Very Basic Numpy array dimension visualization

本秂侑毒 提交于 2020-06-12 04:13:01
问题 I'm a beginner to numpy with no experience in matrices. I understand basic 1d and 2d arrays but I'm having trouble visualizing a 3d numpy array like the one below. How do the following python lists form a 3d array with height, length and width? Which are the rows and columns? b = np.array([[[1, 2, 3],[4, 5, 6]], [[7, 8, 9],[10, 11, 12]]]) 回答1: The anatomy of an ndarray in NumPy looks like this red cube below: (source: Physics Dept, Cornell Uni) Once you leave the 2D space and enter 3D or

Very Basic Numpy array dimension visualization

徘徊边缘 提交于 2020-06-12 04:10:12
问题 I'm a beginner to numpy with no experience in matrices. I understand basic 1d and 2d arrays but I'm having trouble visualizing a 3d numpy array like the one below. How do the following python lists form a 3d array with height, length and width? Which are the rows and columns? b = np.array([[[1, 2, 3],[4, 5, 6]], [[7, 8, 9],[10, 11, 12]]]) 回答1: The anatomy of an ndarray in NumPy looks like this red cube below: (source: Physics Dept, Cornell Uni) Once you leave the 2D space and enter 3D or