1
所以我在.flo
閱讀,因爲我做了一些翹曲。似乎我沒有Python2.7和numpy版本1.11.2的問題,但是當我升級到Python3.6和numpy版本1.12.0時。Numpy只有整數標量數組可以轉換爲標量索引 - 升級到3.6
但在轉換過程中,我知道得到一個錯誤only integer scalar arrays can be converted to a scalar index
爲線data2d = np.fromfile(f, np.float32, count=2 * w * h)
import numpy as np
def read_flow(filename):
f = open(filename, 'rb')
magic = np.fromfile(f, np.float32, count=1)
data2d = None
if 202021.25 != magic:
print('Magic number incorrect. Invalid .flo file')
else:
w = np.fromfile(f, np.int32, count=1)
h = np.fromfile(f, np.int32, count=1)
print("Reading %d x %d flo file" % (h, w))
data2d = np.fromfile(f, np.float32, count=2 * w * h)
# reshape data into 3D array (columns, rows, channels)
data2d = np.resize(data2d, (h, w, 2))
f.close()
return data2d
例.flo
文件可以得到here
工作嘗試'count = int(2 * w * h)' –
@ juanpa.arrivillaga停止抱怨,但現在給出一個空數組,因此不能按預期工作 – redrubia
是的,好吧,如果不知道值'w','h'和你期望的'data2d'爲 –