I'm trying to export an R (1.4.0 on linux) matrix to python (+Pyclimate) via a binary file. The problem is that while R writes by columns, python reads by rows. For a 2D matrix, there is no problem: writeBin writes vectors, so writeBin(t(x)[1:length(x)],...) works fine. But the objects I want to export are 3D arrays (slice rasters of lat,lon for each time t). One way is to use a loop over the 3rd dimension and transpose for each slice, but I've been trying to do something more efficient avoiding the loop. No luck by now, as changing dim(x) to c(dim(x)[2], dim(x)[1]*dim(x)[3]) does not solve the problem. Does anybody have any suggestion? Thanks Agus Dr. Agustin Lobo Instituto de Ciencias de la Tierra (CSIC) Lluis Sole Sabaris s/n 08028 Barcelona SPAIN tel 34 93409 5410 fax 34 93411 0012 alobo at ija.csic.es -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._