np.loadtxt for a file with multiple matrices

I have a file that looks something like this: some text the grids are 3 x 3 more text matrix marker 1 1 3 2 4 7 4 2 9 1 1 new matrix 2 4 9 4 1 1 3 4 4 3 1 new matrix 3 3 7 2 1 1 3 4 2 3 2 .. the file continues, with several 3x3 matrices appearing in

Insert / Add / Update elements in the matrix

Let's say I've initialized a matrix/array that has 400 rows, 3 columns: distances = np.zeros([400, 3], dtype=np.float64) Now, I have a for loop that returns 1200 objects (float values) and I want to "append" each element into distances (row by r

how to add a numpy matrix in an empty array

I want to append a numpy array(matrix) into an array through a loop data=[[2 2 2] [3 3 3]] Weights=[[4 4 4] [4 4 4] [4 4 4]] All=np.array([]) for i in data: #i=[2 2 2 ] #for example h=i*Weights #h=[[8 8 8][8 8 8][8 8 8]] All=np.concatenate((All,h),ax

Taking the transposition of a matrix in C with 1D tables

I have a matrix that is represented by a one dimensional array, example: the matrix 0 1 2 3 4 5 6 7 8 9 10 11 the array 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 now give the dimensions of this matrix and the array I want to find the transpose, i.e. 0, 4,

Calculation of the adjacency of the conditional matrix

I have a matrix, e.g.: set.seed(1) m = matrix(rep(NA,100), nrow=10) m[sample(1:100,10)] = 1 m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA NA NA NA NA NA NA NA NA NA [2,] NA NA NA NA NA NA 1 NA NA NA [3,] NA NA NA NA NA NA NA NA NA NA [

Problems modeling the two-body orbit

Skip to Update 2 below, if you don't want to read too much background. I'm trying to implement a model for simple orbital simulations (two body). However, when I try to use the code I've written, the plots generated from the result look quite odd. Th

Calculate the probability from a table

I have a data frame as following: current state action next state w 1 w w 1 w w 1 o w 1 o o 1 w I want to create a matrix to show that how much is probability of been in next state by taking action1. The martix that I want to have is as following: ne

Fusion of two matrices of different sizes

I have two symmetrical correlation matrices, of which one represents a subset of the other. I want to merge both matrices into long format, to later use this for x,y plots. Here is a small example. library(reshape) library(ggplot2) dist1 <- matrix(ru

Python - read images in the image matrix

I am trying to read multiple rgb images into one matrix, such that the matrix dimensions are (image_size, image_size, index) e.g. data[:,:,1] should retrieve the 1st image. data = np.zeros((image_dim, image_dim, numImages), dtype=np.float64) for fnam

Division of an array and storage in the matrix

I have an array nMean_2 (1-by-16320), I want to divide it into 255 equal parts and store it in matrix (64-by-255) mean2Electro = zeros(64,255); r=1; for z=1:64 mean2Electro(z,:)= nMean_2(r:((z*256)-1)) r= z*256; end But, I am getting an error: ??? Su

How to index and multiply two matrices effectively?

I have two matrices "A", "B", and a data frame "C". They are A <- matrix(1:10, nrow = 2) colnames(A) <- letters[1:5] B <- matrix(11:16, nrow = 2) colnames(B) <- letters[6:8] C <- data.frame(ix1 = c("a"

Create a Function Input Matrix Array in Matlab

I would like to create several matrices to represent Hilbert matrices of different orders. The matrix will then be called by a function. However, error messages appeared saying that the function(GE) is not defined. But if I put the function on top of

R - eliminate duplicate columns in a sparse matrix

I have an R sparse Matrix (very big. not feasible to convert to a full matrix), I want to identify/eliminate duplicate columns if such exist. similar to unique(x,MARGIN=2), but that operates on sparse matrices. is there anything like this around? sug

Initialize the dynamic table

I created a dynamic array in this way: arr = new int*[m]; for(size_t i=0;i<m;++i){ arr[i]=new int[n]; } The values of m and n is 3, I got a matrix which each cell contain 2 or 1 the matrix look like this. {{2,1,2,1}, {1,2,2,2}, {1,1,1,1}, {2,1,1,2}}

How to count the missing data in a matrix?

I have a character matrix B = matrix( c("foo", "--", "bam", "pop", "--", "foo","--","fizz"), nrow=2, ncol=4) Missing data is represented by "--". I'm trying to write

Multiply values ​​in the same position in R

I am working in R and I have two datasets. One dataset contains a contribution amount, and the other includes an include/exclude flag. Below are the data: > contr_df asof_dt X Y 1 2014-11-03 0.3 1.2 2 2014-11-04 -0.5 2.3 3 2014-11-05 1.2 0.4 > inex_

Matlab: Finds nearby instances of NaN without loops

Essentially, I have a matrix of data with many "holes" represented by NaN, and I want to retrieve the indices of all NaN's that are clustered fewer than 4 times in a single column. e.g. with the matrix: A = 23 12 NaN 56 60 21 NaN 60 56 94 22 45

Get the least amount of a combination of matrix elements

Yesterday one of my friend came with a problem, asking me to find the solution. The problem I have a matrix(n x m). I need to find out the least sum what I can produce from those matrix element. The condition is : Counting should only start from the

How to convert a 2x2 card into a list of lists?

Python How do I turn a grid of: x,x x,x to a list of lists?: [['x', 'x'], ['x', 'x']] It's as simple as: with open(...) as f: list_of_lists = [line.strip().split(",") for line in f] # use list_of_lists

Matrix model with all interactions in pairs between columns

Let's say that I have a numeric data matrix with columns w, x, y, z and I also want to add in the columns that are equivalent to w*x, w*y, w*z, x*y, x*z, y*z since I want my covariate matrix to include all pairwise interactions. Is there a clean and

NaN values ​​of the Matlab comparison tool

I am trying to compare two .mat files using the Matlab Comparison Tool. In the comparison result the NaN values are highlighted meaning they are different (even though they are not). How can one handle the NaN values when using the Matlab Comparison

Row intersection index

Given these two matrices: m1 = [ 1 1; 2 2; 3 3; 4 4; 5 5 ]; m2 = [ 4 2; 1 1; 4 4; 7 5 ]; I'm looking for a function, such as: indices = GetIntersectionIndecies (m1,m2); That the output of which will be indices = 1 0 0 1 0 How can I find the intersect

Search Values ​​from a Matrix Based on Line Data (MATLAB)

I have something like the following: X = [1 5; 2 5; 3 7; 4 7; 5 2; 6 7]; X = 1 5 2 5 3 7 4 7 5 2 6 7 b = [1;4;6]; b = 1 4 6 Is there a way to lookup the values (from X), input as b, to output the following: b1 = 1 5 4 7 6 7 If you're sure that the va

Rotate image + horizontal or vertical flip

I'm developing an html5 canvas image application where you could make basic transformation like 90ยบ rotation, flip horizontal and vertical. I use the following matrix to paint the image: matrix.scale(flipHorizontal, flipVertical); // Where each flip

Selecting elements from a matrix in matlab

I have a matrix which is 36 x 2, but I want to seperate the elements to give me 18, 2 x 2 matrices from top to bottom. E.g. if I have a matrix: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ... ... I want to split it into seperate matrices: M1 = 1 2 3 4 M2 = 5 6

Vector of the sum of different diagonals in a matrix

I want to vectorize the following MATLAB code. I think it must be simple but I'm finding it confusing nevertheless. r = some constant less than m or n [m,n] = size(C); S = zeros(m-r,n-r); for i=1:m-r+1 for j=1:n-r+1 S(i,j) = sum(diag(C(i:i+r-1,j:j+r-

allocate the matrix in C

i want to allocate a matrix. is this the only option: int** mat = (int**)malloc(rows * sizeof(int*)) for (int index=0;index<row;++index) { mat[index] = (int*)malloc(col * sizeof(int)); } Well, you didn't give us a complete implementation. I assume th