1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

read big-endian 32bit float data using ruby numo/narray

Posted at

TL;DR

big-endian 32bit floatのデータをファイルから読み込み、Narrayオブジェクト化する。

Version

  • Ruby: 3.0.2p107
  • numo-narray: 0.9.2.0

Install

gem install numo-narray

Code

require "numo/narray"
include Numo

file_name = "PSEA.f32"
io = open(file_name, "rb")

grid = {:x => 481, :y => 505}

#読み込み
data = SFloat.from_string(io.read(grid[:x] * grid[:y] * 4))

#エンディアン変換
data = data.swap_byte

#整形
data.reshape!(grid[:x], grid[:y])

p data

io.close

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?