[R] R matrix to Python
Martin Maechler
maechler at stat.math.ethz.ch
Wed Mar 13 12:04:52 CET 2002
>>>>> "AgusL" == Agustin Lobo <alobo at ija.csic.es> writes:
AgusL> I'm trying to export an R (1.4.0 on linux) matrix to
AgusL> python (+Pyclimate) via a binary file. The problem is
AgusL> that while R writes by columns, python reads by
AgusL> rows. For a 2D matrix, there is no problem: writeBin
AgusL> writes vectors, so writeBin(t(x)[1:length(x)],...)
AgusL> works fine.
AgusL> But the objects I want to export are 3D arrays (slice
AgusL> rasters of lat,lon for each time t). One way is to
AgusL> use a loop over the 3rd dimension and transpose for
AgusL> each slice, but I've been trying to do something more
AgusL> efficient avoiding the loop. No luck by now, as
AgusL> changing dim(x) to c(dim(x)[2], dim(x)[1]*dim(x)[3])
AgusL> does not solve the problem. Does anybody have any
AgusL> suggestion?
Yes: aperm() is the generalization of t().
Hence use it for higher rank arrays as you used t() for matrices.
Martin
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list