matrix - How to resolve integer overflow in r? -
i have created matrix (mata) of 1000 rows , 1000 columns, , want calculate powers of matrix. works calculating 3rd power of matrix. when ask calculate 4th power, gives warning message saying,
"in mata * mata * mata * mata : nas produced integer overflow"
how can resolve problem?
since didn't give example:
set.seed(101) z <- matrix(rnorm(1e6),1e3) z2 <- round(z)*1000000 storage.mode(z2) <- "integer"
if want matrix power (as in z2 %*% z2 %*% z2 %*% z2
), it's best use matrix
or expm
package.
library(expm) z4c <- z2 %^% 4
on other hand, if want elementwise product
z4d <- z2*z2*z2*z2 ## warning message "nas produced"
all need convert numeric.
storage.mode(z2) <- "numeric" z4e <- z2*z2*z2*z2 ## fine
Comments
Post a Comment