On Thu, 24 Feb 2022 11:00:08 -0500
Paul Bernal <paulberna...@gmail.com> wrote:

> Each pixel column in the training set has a name like pixel x, where
> x is an integer between 0 and 783, inclusive. To locate this pixel on
> the image, suppose that we have decomposed x as x = i ∗ 28 + j, where
> i and j are integers between 0 and 27, inclusive. 

> I have been looking for information about how to process this with R,
> but have not found anything yet.

Given a 784-element vector x, you can reshape it into a 28 by 28 matrix:

dim(x) <- c(28, 28)

Or create a new matrix: matrix(x, 28, 28)

Working with more dimensions is also possible. A matrix X with dim(X)
== c(n, 784) can be transformed into a three-way array in place or
copied into one:

dim(X) <- c(dim(X)[1], 28, 28)
array(X, c(dim(X)[1], 28, 28))

(Replace 28,28 with 784 for an inverse transformation. In modern
versions of R, two-way arrays are more or less the same as matrices,
but old versions may disagree with that in some corner cases.)

For more information, see ?dim, ?matrix, ?array.

-- 
Best regards,
Ivan

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to