[BioC] function to find coodinates in an array
lgautier at altern.org
lgautier at altern.org
Thu Aug 16 22:27:42 CEST 2007
> Dear list,
>
> I am looking for a function/way to get the array coordinates of given
> elements in an array. What I mean is the following:
> - Let X be a 3D array
> - I find the ordering of the elements of X by ord <- order(X) (this
> returns me a vector)
> - I now want to find the x,y,z coordinates of each element of ord
>
> Can anyone help me?
...cross-posting is generally not advised. Identify where to post first
is generally considered good practice.
In case no one on R-help came with a solution, here
is something that appears working (in toy examples):
# the easy one first
Xx <- array(rep(seq(1, prod(dim(X)[1])), prod(dim(X)[c(2,3)])), dim(X))
# then making the other ones easy
Xy <- local({
X <- aperm(X, c(2, 1, 3))
Xy <- array(rep(seq(1, prod(dim(X)[1])), prod(dim(X)[c(2,3)])),
dim(X))
aperm(Xy, c(2, 1, 3))
})
Xz <- local({
X <- aperm(X, c(3, 2, 1))
Xz <- array(rep(seq(1, prod(dim(X)[1])), prod(dim(X)[c(2,3)])),
dim(X))
aperm(Xz, c(3, 2, 1))
})
# what you want:
Xx[ord]
Xy[ord]
Xz[ord]
L.
> Thanks!
>
> Ana
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>
More information about the Bioconductor
mailing list