matrix

Changing value when multiple rows/columns combined do not meet a requirement

安稳与你 提交于 2020-01-06 04:08:05
问题 Relatively new to R, working on a project with millions of rows so I made this example: I've got a matrix with three different rows of data. If the combination of [,1][,2][Farm] has less then two observations in total, the [Farm] value of that row gets changed to q99999. This way they fall in the same group for later analysis. A <- matrix(c(1,1,2,3,4,5,5), ncol = 7) B <- matrix(c(T,T,F,T,F,T,T), ncol = 7) C <- matrix(c("Req","Req","Req","fd","as","f","bla"), ncol = 7) AB <- rbind.fill.matrix

Rotating a 4x4 Matrix Causes Scaling Over Time

无人久伴 提交于 2020-01-06 03:26:11
问题 I am using glm::rotate to rotate a transformation matrix for a cube in a scene. "cube->t = glm::rotate(cube->t, stepTime * 50.f, glm::vec3(0.f, 1.f, 0.f));" is called once per frame, where cube->t is the matrix in question. The strange thing is that over the course of 20 minutes (or two minutes if I rotate by stepTime * 5000.f instead of stepTime * 50.f ), the cube scales noticeably on the X and Z axes, where the scaling on those two axes is the same at all times (the height of the cube never

(Matlab) Dimensional indexing using indices returned by min function

99封情书 提交于 2020-01-06 02:18:32
问题 Suppose I have a 5-d matrix C. I use the following code to get a min matrix C3 (each element of C3 represents the minimum of dimension 1,2,3): [C1, I1] = min(C,[],1); [C2, I2] = min(C1, [], 2); [C3, I3] = min(C2, [], 3); The question is how to get the index of the minimum in terms of each dimension? For example consider this simpler case: C = [1,2;3,4] The minimum here is 1, its index in dimension 1 is 1 (first row) and in dimension 2 also 1 (first column). I know that changing the sequence

Is it possible to solve a non-square under/over constrained matrix using Accelerate/LAPACK?

眉间皱痕 提交于 2020-01-05 19:22:59
问题 Is it possible to solve a non-square under/over constrained matrix using Accelerate/LAPACK? Such as the following two matrices. If any variables are under constrained they should equal 0 instead of being infinite. So in the under constrained case: A, D & E would equal 0, while B, C & F equal -1. In the over constrained case all variables would be equal to -1. Under Constrained: ____ ____ | (A) (B) (C) (D) (E) (F) | | -1 0 0 1 0 0 | 0 | | 1 0 0 0 -1 0 | 0 | | 0 -1 1 0 0 0 | 0 | | 0 1 0 0 0 -1

python: list of matrices to numpy array?

泄露秘密 提交于 2020-01-05 14:12:13
问题 I've got a list containing numpy matrices. Anyway that I could turn the whole thing into a nice clean numpy array? From: [matrix([[1]]), matrix([[ 1.99387871]]), matrix([[ 2.53564618]]), matrix([[ 4.39125807]]), matrix([[ 4.246309]]), matrix([[ 5.21571607]]), matrix([[ 6.17408811]]), matrix([[ 4.75146571]]), matrix([[ 6.19319742]]), matrix([[ 6.1277607]]), matrix([[ 7.43821216]])] To: [[1 1.99387871 2.53564618 4.39125807 4.246309 5.21571607 6.17408811 4.75146571 6.19319742 6.1277607 7

Matrix manipulation to extract certain sub columns

匆匆过客 提交于 2020-01-05 13:06:45
问题 M = [1007 1007 4044 1007 4044 1007 5002 5002 5002 622 622; 552 552 300 552 300 552 431 431 431 124 124 ; 2010 2010 1113 2010 1113 2010 1100 1100 1100 88 88; 7 12 25 15 12 30 2 10 55 32 12] X = {[2 5 68 44],[2 10 55 9 17],[1 55 6 7 8 9],[32 12]} A = [1007 4044 5002 622 552 300 431 124 2010 1113 1100 88 7 25 2 32 12 12 10 12 15 55 30 ] A is an entity to explain what I want. A contains unique column vectors of M(1:3,:) , in addition to the corresponding values in M(4,:) A(1:3,:) = unique(M(1:3,:

Matrices whose entries are polynomials

ⅰ亾dé卋堺 提交于 2020-01-05 12:23:49
问题 When using the sympy library, what is the most efficient way of operating with matrices whose entries are polynomials? I tried both storing symbols and storing Poly instances as entries of a Matrix object. In each case, the performance that I get for operations like matrix multiplication seems to be an order of magnitude slower than what I get with sage . 来源: https://stackoverflow.com/questions/24931740/matrices-whose-entries-are-polynomials

How to process a integer matrix to find the average for the elements of any sub-rectangle in O(1)?

丶灬走出姿态 提交于 2020-01-05 11:07:05
问题 This is an interview question: How to process a integer matrix to find the average for the elements of any sub-rectangle in O(1)? As the comments say, we should calculate the prefix sums. Well, it is embarrassing but even having asked a similar question I did not get it. 回答1: See @Sven Marnach'answer to the post @Michael linked to. The prefix sum algorithm he outlines is based on the following idea: if you have precomputed the sums of the following element sequences: [0, 0], [0, 1], [0, 2], .

gsl complex matrix * complex vector

ぐ巨炮叔叔 提交于 2020-01-05 10:26:11
问题 Can somebody help me figure out how to do this operation. I'm looking at the documentation, but its been so long since I've had to do any linear algebra type stuff I'm a little lost. I have a 14x14 complex matrix called Y and a complex vector called I. I need to multiply them and set the result to a complex vector named IL. So far I have figured out that I need to use: gsl_blas_zgemv (CBLAS_TRANSPOSE_t TransA, const gsl_complex alpha, const gsl_matrix_complex * A, const gsl_vector_complex * x

Trying to solve a system of linear equations in matlab

半腔热情 提交于 2020-01-05 09:02:52
问题 I've been set a question asking me to solve a system of linear equations. In the question it states I should set up a matrix A and column vector b to solve the equation A x = b , where x is the column vector (w x y z). A = [1 1 1 1; 0 1 4 -2; 2 0 -2 1; 1 -2 -1 1] b = [28;7;22;-4] A1 = inv(A).*b sum(A1,2) This is what I've done so far, however I know the answer that MATLAB gives me is incorrect, as the right solutions should be w=10.5, x=9, y=2.5, z=6. Can someone point me in the right