ファイルオブジェクトの位置とはどういう意味なのでしょうか?
http://www.buildinsider.net/small/booktensorflow/0201
を参考にして今Tensorflowの勉強をしています。
# -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import division from __future__ import print_function import os import numpy as np class Cifar10Record(object): width = 32 height = 32 depth = 3 def set_label(self,label_byte): self.label = np.frombuffer(label_byte,dtype=np.uint8) def set_image(self,image_bytes): byte_buffer = np.frombuffer(image_bytes,dtype=np.int8) reshaped_array = np.reshape(byte_buffer,[self.depth,self.height,self.width]) self.byte_array = np.transpose(reshaped_array,[1,2,0]) self.byte_array = self.byte_array.astype(np.float32) class Cifar10Reader(object): def __init__(self,filename): if not os.path.exists(filename): print(filename + ' is not exist') return self.bytestream = open(filename,mode="rb") def close(self): if not self.bytestream: self.bytestream.close() def read(self,index): result = Cifar10Record() label_bytes = 1 image_bytes = result.height * result.width * result.depth record_bytes = label_bytes + image_bytes self.bytestream.seek(record_bytes * index,0) result.set_label(self.bytestream.read(label_bytes)) result.set_image(self.bytestream.read(image_bytes)) return result
というコードを書きました。
しかし、以下の部分がわからないです。
self.bytestream.seek(record_bytes * index,0)
このseekメソッドを調べたときに
ファイルオブジェクトの位置を変更するには、f.seek(offset, from_what) を使います。ファイル位置は基準点 (reference point) にオフセット値 offset を足して計算されます。
という説明が書いてありました。
https://docs.python.jp/3/tutorial/inputoutput.html
しかし、この、ファイルオブジェクトの位置がどういう意味なのか分かりません。
オフセット値 offsetがどういうものなのかはわかります。
http://e-words.jp/w/%E3%82%AA%E3%83%95%E3%82%BB%E3%83%83%E3%83%88.html
この部分は、メモリの位置を指定してデータを計算させるのに必要ということなのでしょうか?
ファイルオブジェクトの位置は何を意味しているのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。