Raising a matrix's digits to the power of a sequence fast?

46 Views Asked by At

There is a matrix called A, which is an n x k matrix. It's digits are in complex forms. I'm trying to raise each row of matrix A to the rownum(th) exponent.

n <- 1000
k <- 10
x <- complex(real = runif(n*k), imaginary = runif(n*k))
A <- matrix(x, ncol = k, nrow = n)

Exponent_Matrix <- matrix(1:n, ncol = k, nrow = n)

Result <- A^Exponent_Matrix

library(microbenchmark)

microbenchmark(
  Result <- A^Exponent_Matrix,
  times = 1000
)
#0.000487secs

This is a solution that works, but it could it be done in a more efficient way? Also, the length of the matrix (n) can vary, but the colnum (k) is usually between 1 and 20.

0

There are 0 best solutions below