Я читаю файлы изображений MNIST в R, используя функцию, основанную на readBin()
.Однако, запуская функцию построчно, я вижу, что readBin()
возвращает разные значения для одной и той же строки кода (без каких-либо изменений параметров).Как получилось?
#Getting the data
> download.file("http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz",
+ "t10k-images-idx3-ubyte.gz")
#unzipped the .gz file manually out of R. The extracted file is 'train-images.idx3-ubyte'
#Using file() to read the 'train-images.idx3-ubyte' file
> f = file("train-images.idx3-ubyte", 'rb')
#this is what 'f' is:
> f
A connection with
description "train-images.idx3-ubyte"
class "file"
mode "rb"
text "binary"
opened "opened"
can read "yes"
can write "no"
#The following lines show the execution of readBin with the same parameters, though giving a different value each time
> readBin(f, 'integer', n = 1, size = 4, endian = 'big')
[1] 2051
> readBin(f, 'integer', n = 1, size = 4, endian = 'big')
[1] 60000
> readBin(f, 'integer', n = 1, size = 4, endian = 'big')
[1] 28
> readBin(f, 'integer', n = 1, size = 4, endian = 'big')
[1] 28
> readBin(f, 'integer', n = 1, size = 4, endian = 'big')
[1] 0