[R] Pixel Image Reshaping using R

Paul Bernal p@u|bern@|07 @end|ng |rom gm@||@com
Thu Feb 24 19:12:16 CET 2022


Dear Ivan, this is what I did:

dataframe_train <- as.matrix((read.csv(file_path_2, header=TRUE,
stringsAsFactors = FALSE)))
dim(dataframe_train) <- c(28,28)
The file I read was the one I attached in the first email. Would this do
the work to reshape original dataset into a 28 x 28 matrix? When I print
the original dataframe I get the message: [ reached getOption("max.print")
-- omitted 41999 rows ] this only means that R will not pront the whole
data, but is not trimming anything right?

Best regards,
Paul


El jue, 24 feb 2022 a las 12:00, Ivan Krylov (<krylov.r00t using gmail.com>)
escribió:

> On Thu, 24 Feb 2022 11:00:08 -0500
> Paul Bernal <paulbernal07 using 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
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list