Sum matrices without using Loops

I have a project where many matrices will need to be summed together. Currently, this is accomplished through a while loop for each iteration. Is there a faster way to sum matrices using maybe built in programming? From my research so far, all matr...
more »

2017-07-18 20:07 (1) Answers

Fill a matrix from a matrix of indices

I want to fill a matrix from an array of indices : import numpy as np indx = [[0,1,2],[1,2,4],[0,1,3],[2,3,4],[0,3,4]] x = np.zeros((5,5)) for i in range(5): x[i,indx[i]] = 1. The result is : array([[ 1., 1., 1., 0., 0.], [ 0., 1...
more »

2017-07-14 19:07 (1) Answers

How does this one-hot vector conversion work?

When I was working on my machine learning project, I was looking for a line of code to turn my labels into one-hot vectors. I came across this nifty line of code from u/benanne on Reddit. np.eye(n_labels)[target_vector] For example, for a target_...
more »

2017-07-13 01:07 (1) Answers

Function to return modified matrix in R

The following code adds vector XTS1$XTSSum2 to xts object XTS1: library(xts) XTS1 <- structure(c(12, 7, 7, 22, 24, 30, 26, 23, 27, 30), .indexCLASS = c("POSIXct", "POSIXt"), .indexTZ = "", tclass = c("POSIXct", "POSIXt"), tzone = "", class = c("x...
more »

2017-07-10 23:07 (1) Answers

How do I build this block matrix in python?

I want to build a block matrix for a system of equation with n points. The result is an (2n+2)x(2n+2) matrix. In example, for 2 points the matrix is: 1 0 0 0 0 0 a b c d 0 0 e f g h 0 0 0 0 a b c d 0 0 e f g h 0 0 0 0 0 1 For 3 points the matrix...
more »

2017-07-06 21:07 (3) Answers

Compare matrices in Python and store results

I would like to compare a 70x1 matrix with a 1000x3 matrix. What i want to do is compare the first column of the second matrix with the first matrix, find all the common values and then store the results in a new third matrix which is going to have a...
more »

2017-07-05 12:07 (3) Answers

Fill matrix with function output R

I'm trying to fill a matrix with the outputs of a function at each instance of the matrix. I either get the error "replacement has length zero" or "number of items to replace is not a multiple of replacement length". Please help! setPoint <- fun...
more »

2017-07-04 19:07 (1) Answers

Python Memory Error - Numpy Matrix (1568x1568)

I have two very similar programs whose functions differ only slightly. Within both programs, a 1568 x 1568 numpy matrix is produced. In one of my programs, this matrix creation works perfectly, however, in the other, I receive a MemoryError. Error me...
more »

2017-07-04 10:07 (1) Answers

np.loadtxt for a file with many matrixes

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 matri...
more »

2017-06-30 22:06 (2) Answers

Populating a matrix in TensorFlow

So I'm trying to populate a matrix in TensorFlow, the size of this matrix changes depending on the inputs so I'm using TensorArray to do it. Essentially, the Numpy equivalent of this is: areas = np.zeros((len(rows)-1,len(cols)-1)) for r in range(len...
more »

2017-06-27 23:06 (1) Answers

Find a matrix which satisfies certain constraints

Another description of the problem: Compute a matrix which satisfies certain constraints Given a function whose only argument is a 4x4 matrix (int[4][4] matrix), determine the maximal possible output (return value) of that function. The 4x4 matrix ...
more »

2017-06-27 15:06 (3) Answers

maximal positive submatrices using haskell

I have following problem: You are given matrix m*n and you have to find maximal positive ( all elements of submatrix should be >0 ) submatrices from (1,1) to (x,y). What do I mean by maximal is, when you have following matrix: [[1,2,3,4],[5,6,7,...
more »

2017-06-26 12:06 (1) Answers

Triple for loop in matrix scanning

As say in the title i'm actually using a triple for loop to treat a numpy matrix called A in my python program and , as we can expect, it's very slow. I have a function that we gonna call "return_bool" which return a boolean in function of a paramete...
more »

2017-06-26 11:06 (1) Answers

Calling a 2D array function?

I first apologize if some of you find my problem stupid and easy to solve, but I am a very beginner in "c". My task is to create an inverse of a 3x3 matrix using different functions. What I am trying to do now is to tell the user to input values f...
more »

2017-06-23 08:06 (4) Answers

R - Faster sorting of matrix product

There are 2 matrices A and B. A is of size 2M*50, B is 20k*50. I want to compute the top 10 values of A %*% t(B) for each row. I was wondering if there is a faster implementation than this one library(parallel) library(pbapply) set.seed(1) A <-...
more »

2017-06-21 00:06 (1) Answers

Write a for loop in a function to get a matrix

I need to put delta.vec and sigma.vec values through my required.replicates function and store them in my practice1 matrix. But I get NULL. sigma.vec <- c(2,4,6,8,10,12) delta.vec <- c(1,2,5,8,10) practice1 <- matrix(0, nrow=length(delta...
more »

2017-06-17 14:06 (1) Answers

Dealing With Matrices in Python

I am new to python and facing a problem in dealing with Matrices. I have a matrix, let's say A = [1 0 0 2; 3 3 3 2; 3 3 0 2; 3 4 4 4] Now, I want to make all the elements in the matrix equal to zero, except elements which are repeated the maximum...
more »

2017-06-12 08:06 (4) Answers