Displaying 20 results from an estimated 3000 matches similar to: "How to 'explode' a matrix"
2011 Jan 05
4
Match numeric vector against rows in a matrix?
Two posts in one day is not a good day...and this question seems like it should have an obvious answer:
I have a matrix where rows are unique combinations of 1's and 0's:
> combs=as.matrix(expand.grid(c(0,1),c(0,1)))
> combs
Var1 Var2
[1,] 0 0
[2,] 1 0
[3,] 0 1
[4,] 1 1
I want a single function that will give the row index containing an exact match
2012 Jan 28
2
Need very fast application of 'diff' - ideas?
Hi everyone,
Speed is the key here.
I need to find the difference between a vector and its one-period lag (i.e. the difference between each value and the subsequent one in the vector). Let's say the vector contains 10 million random integers between 0 and 1,000. The solution vector will have 9,999,999 values, since their is no lag for the 1st observation.
In R we have:
#Set up input vector
2011 Apr 14
3
Find number of elements less than some number: Elegant/fast solution needed
Take vector x and a subset y:
x=1:10
y=c(4,5,7,9)
For each value in 'x', I want to know how many elements in 'y' are less than 'x'.
An example would be:
sapply(x,FUN=function(i) {length(which(y<i))})
[1] 0 0 0 0 1 2 2 3 3 4
But this solution is far too slow when x and y have lengths in the millions.
I'm certain an elegant (and computationally efficient)
2005 Jul 13
2
Kronecker matrix product
Hi
I want to write a little function that takes a matrix X of size
m-by-n, and a list L of length "m", whose elements are matrices all
of which have
the same number of columns but possibly a different number of rows.
I then want to get a sort of dumbed-down kronecker product in which
X[i,j] is replaced by X[i,j]*L[[j]]
where L[[j]] is the j-th of the "m" matrices. For
2011 Jun 05
2
kronecker sum
Dear All,
Could someone please suggest how to find the Kronecker sum of two 2x2
matrices,
i.e. given two matrices:
-A A
a -a
and
-B B
b -b
I need:
-A-B A B 0
a -a-B 0 B
b 0 -A-b A
0 b a -a-b
Many thanks,
Lara
[[alternative HTML version deleted]]
2005 Nov 08
2
Ruby equivalent of PHP Explode / Implode
Anyone know what the Ruby equivalent of PHP''s explode and implode are
for arrays?
- Jim
2009 Dec 12
1
Create sequence given start and end vector
How can I create the following without the 'for' loop?
start=c(1,10,20)
end=c(4,15,27)
out=c()
for (i in 1:length(start)) {
out=c(out,start[i]:end[i])
}
out
[1] 1 2 3 4 10 11 12 13 14 15 20 21 22 23 24 25 26 27
I know there must be an easier (and, hopefully, faster) way.
Many thanks in advance,
Kevin Ummel
Central European University
Department of Environmental Science and
2013 Feb 23
1
how to calculate left kronecker product?
For an application, I have formulas defined in terms of a left Kronecker
product of matrices,
A,B, meaning
A \otimes_L B = {A * B[i,j]} -- matrix on the left multiplies each
element on the right.
The standard kronecker() function is the right Kronecker product,
A \otimes_R B = {A[i,j] * B} -- matrix on the right multiplies each
element on the left.
The example below shows the result of
2005 Dec 08
1
kronecker(... , make.dimnames=TRUE)
Hi
I'm using kronecker() with a matrix and a vector. I'm interested in
the column names that kronecker() returns:
> a <- matrix(1:9,3,3)
> rownames(a) <- letters[1:3]
> colnames(a) <- LETTERS[1:3]
> b <- c(x=1,y=2)
> kronecker(a,b,make.dimnames=TRUE)
A: B: C:
a:x 1 4 7
a:y 2 8 14
b:x 2 5 8
b:y 4 10 16
c:x 3 6 9
c:y 6 12 18
>
The
2012 Feb 09
1
Row-wise kronecker product with Matrix package
I'm trying to calculate the row-wise kronecker product A \Box B of two
sparse matrices A and B, and am struggling to find a quick way to do this
that takes advantage of sparseness. I thought a good idea would be to use
"rep" to construct 2 matrices of the same dimension of the end product, and
multiply these two together:
library(Matrix)
A<-Matrix(c(1,0,0,0,0,1,2,0), 2, 4)
2010 Nov 16
2
Pass character vector to function argument
A bit embarrassed to post this seemingly trivial question, but I can't find anything in the archive that's quite relevant:
a1=1
a2=2
obs=objects(pattern=glob2rx("a?"))
I want to utilize 'obs' as a function argument to produce something like:
sum(a1,a2)
Obviously, sum(obs) doesn't work, but I've tried variations of 'eval', 'parse',
2006 Jun 03
0
How to "explode" tc rules maked by HTB.init?
Hi to all,
i''m using htb.init for configuring my shaper.
Now i want to know if it possible to show how htb.init make and use
TC, anyone has tried it?
Many thanks.
--
Stefano Mainardi
Presidente Associazione ILDN - Italian Linux Distro Network
Mobile: 349/3917212
Skype: mainardistefano
IM (ICQ): 250-292-408
Blog: http://www.mainardistefano.org
2010 Nov 25
1
Request: kronecker to get a sep= argument
kronecker, with make.dimnames=TRUE uses a hardwired sep=":" in the line
tmp <- outer(dnx[[i]], dny[[i]], FUN = "paste", sep = ":")
For an application in which dimnames arise from an n-way array, where
different dimensions have
different roles, and I would like to be able to use kronecker in the form
kronecker(A, B, make.dimnames=TRUE,
2004 Oct 01
2
multiple dimensional diag()
Hi
I have two arbitrarily dimensioned arrays, "a" and "b", with
length(dim(a))==length(dim(b)). I want to form a sort of
"corner-to-corner" version of abind(), or a multidimensional version
of blockdiag().
In the case of matrices, the function is easy to write and if
a=matrix(1,3,4) and b=matrix(2,2,2), then adiag(a,b) would return:
[,1] [,2] [,3] [,4] [,5]
2005 Oct 13
3
Help with Matrix package
Hello all,
A colleague at work set me the challenge to convert some MATLAB
code into R, to see which is faster. We'd seen that benchmark comparing
MATLAB 6.5 to R1.90 (and others), and so I thought that I should be able
to get roughly comparable speeds. The code has lots of multiplications
of matrixes, transposes, and MATLAB's "repmat". I did the code
conversion, and R was about
2009 May 30
1
Spatiotemporal correlation function
Hi,
I'm trying to compute the spatiotemporal correlation matrix by using Delta Kronecker products of spatial and temporal correlation matrix in R, but didn't find any delta Kronecker's operator in R. The operators in matrix such as multiplication, addition, eigen values/vector and etc is easily to find and used.
Could someone help me, please?
Cheers.
Firdaus
2012 Jun 09
2
Matrix package loading problem "Error : object ‘kronecker’ is not exported by 'namespace:methods'"
Hi R users all ,
I have a clean install of R-2.15.0 in a win32 machine and a problem loading
Matrix 1.0-6 that looks like this:
> library(Matrix)
Loading required package: lattice
Error : object ?kronecker? is not exported by 'namespace:methods'
Error: package/namespace load failed for ?Matrix?
>
I understand that kronecker() now has an S4 generic in package methods. Is
that a
2004 Sep 28
2
S4 method selection based on second argument
I'm translating some Matlab code and need some help figuring
out how to change this call into an S4 generic method.
In matlab, there's a function called 'repmat' with three
calling sequences (all I have to deal with anyway):
1) B = repmat(A, m, n)
2) B = repmat(A, [m n])
3) B = repmat(A, n)
In all cases, A is the fill value, m is number of rows,
and n is number of
2012 Dec 08
5
How to efficiently compare each row in a matrix with each row in another matrix?
Dear expeRts,
I have two matrices A and B. They have the same number of columns but possibly different number of rows. I would like to compare each row of A with each row of B and check whether all entries in a row of A are less than or equal to all entries in a row of B. Here is a minimal working example:
A <- rbind(matrix(1:4, ncol=2, byrow=TRUE), c(6, 2)) # (3, 2) matrix
B <-
2009 Feb 23
1
trade-off between speed and storage in matrix multiplications
Dear R-users,
I coded two equivalent ways to perform (in a simplified version)
some matrix multiplications I would like to use in a more general
framework.
In the first case I used Kronecker product and vectorization of a
certain matrix. This approach takes less time, but, as you may guess, I
run out of memory when dimensions are large.
In the second approach, I profited of sparseness and