matrix

Accessing pandas DataFrame as a nested list

时光怂恿深爱的人放手 提交于 2019-12-25 09:43:12
问题 I've used the .set_index() function to set the first column as my index to the rows in my dataframe: >>> import pandas as pd >>> df = pd.DataFrame([['x', 1,2,3,4,5], ['y', 6,7,8,9,10], ['z', 11,12,13,14,15]]) >>> df.columns = ['index', 'a', 'b', 'c', 'd', 'e'] >>> df = df.set_index(['index']) >>> df a b c d e index x 1 2 3 4 5 y 6 7 8 9 10 z 11 12 13 14 15 How should the dataframe be manipulated such that I can be accessed like a nested list? e.g. are the following possible: >>> df['x'] [1, 2

Creating Huge Sparse Matrices in python

為{幸葍}努か 提交于 2019-12-25 09:29:42
问题 I have been using normal matrices from numpy to store a Matrix for a physics project. The size of the matrix is determined by the physical system. So for instance if the system has parameters: L=4 and N =2, then the matrix is of dimension 4C2 = 6, so the matrix is a 6x6 matrix. This is fine except for now I need larger size i.e 20C10 = 184,756. So the matrix required is now a 184756x184756 matrix, which when I try to create an empty matrix of this size gives me a memory error. (with 16GB of

Decomposition of matrices for CPLEX and machine learning application

房东的猫 提交于 2019-12-25 09:19:20
问题 I am dealing with big matrices and time to time my code ends with 'killed:9' message in my terminal. I'm working on Mac OSx. A wise programmer tells me the problem in my code is liked to the stored matrix I am dealing with. nn = 35000 dd = 35 XX = np.random.rand(nn,dd) XX = XX.dot(XX.T) #it should be faster than np.dot(XX,XX.T) yy = np.random.rand(nn,1) XX = np.multiply(XX,yy.T) I have to store this huge matrix XX, my guess: I split the matrix with upp = np.triu(XX) Do I actually save space

Rotating an Object Around an Axis

♀尐吖头ヾ 提交于 2019-12-25 09:19:03
问题 I have a circular shape object, which I want to rotate like a fan along it's own axis. I can change the rotation in any direction i.e. dx, dy, dz using my transformation matrix. The following it's the code: Matrix4f matrix = new Matrix4f(); matrix.setIdentity(); Matrix4f.translate(translation, matrix, matrix); Matrix4f.rotate((float) Math.toRadians(rx), new Vector3f(1,0,0), matrix, matrix); Matrix4f.rotate((float) Math.toRadians(ry), new Vector3f(0,1,0), matrix, matrix); Matrix4f.rotate(

How to return matrix?

雨燕双飞 提交于 2019-12-25 09:17:19
问题 I'm trying to make a Cramer-linear-solving, and I wrote a function that replaces a matrix column, just like that: void replacecol(int c, int n, float mat_in[n][n], float vect_in[n], float mat_out[n][n]) { int i, j; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { if (j == c) { mat_out[i][j] = vect_in[j]; } else { mat_out[i][j] = mat_in[i][j]; } } } } But it is currently void, and I want it to return the mat_out with it's values, when I call this function... How could I do that?? 回答1: You

apply rotate transformation in old matrix android

删除回忆录丶 提交于 2019-12-25 09:14:30
问题 I have a matrix for transforming an image. Old matrix is a function of a scale and translation. Now how to apply rotation from center in old Matrix without affecting the other transformation like scale and translation. i already try this //get old matrix Matrix matrix = getImageMatrix(); float tx = getMatrixValue(matrix, Matrix.MTRANS_X); float ty = getMatrixValue(matrix, Matrix.MTRANS_Y); float scaleX = getMatrixValue(matrix, Matrix.MSCALE_X); float scaleY = getMatrixValue(matrix, Matrix

R - repeatedly cbind a matrix & a vector of unequal length -> vector goes into new column and not overwrite empty cells of previous columns

戏子无情 提交于 2019-12-25 09:04:41
问题 I need to repeatedly add a vector to a matrix. Both take on different lengths everytime I do this. The complete matrix is then used for further analysis (plotting, t-test) Three months ago this code worked: mlen <- max(length(matrix), length(vector)) length(maxtrix) <- length(vector) <- mlen matrix <- cbind(matrix, vector) I don't use any specific packages for that. Data input is unchanged a csv file. Now I have either of the following the issues: a) the unequal length function doesn't work

R: Searching & isolating multiple first occurences in time series

岁酱吖の 提交于 2019-12-25 08:58:37
问题 I am trying to write a function that allows me to find multiple first occurences of an event in a given year. Events happen to different firms at different moments in time. So an event might happen for the first time in 1980 to firm c and afterwards in 1981 to firm b. In that case, all i need to find is firm c_1980 and the associated value in the matrix. If however, an event does NOT happen UNTIL it happens to firm a in 1986 and to firm e in 1986 as well, then I need to find as outcome both a

Theano row/column wise subtraction

怎甘沉沦 提交于 2019-12-25 08:14:54
问题 X is an n by d matrix, W is an m by d matrix, for every row in X I want to compute the squared Euclidean distance with every row in W , so the results will be an n by m matrix. If there's only one row in W , this is easy x = tensor.TensorType("float64", [False, False])() w = tensor.TensorType("float64", [False])() z = tensor.sum((x-w)**2, axis=1) fn = theano.function([x, w], z) print fn([[1,2,3], [2,2,2]], [2,2,2]) # [ 2. 0.] What do I do when W is a matrix (in Theano)? 回答1: Short answer, use

Build adjacency matrix from list of weighted edges in BigQuery

寵の児 提交于 2019-12-25 08:05:04
问题 Related issue: How to create dummy variable columns for thousands of categories in Google BigQuery I have a table of list of weighted edges which is a list of user-item rating, it looks like this: | userId | itemId | rating | 001 | 001 | 5.0 | 001 | 002 | 4.0 | 002 | 001 | 4.5 | 002 | 002 | 3.0 I want to convert this weighted edge list into a adjacency matrix: | userId | item001 | item002 | 001 | 5.0 | 4.0 | 002 | 4.5 | 3.0 According to this post, we can do it in two steps, the first step is