From 3a0beeb7e3adc5b15f3c8e1221c52ad483d812d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francisco=20Carrillo=20P=C3=A9rez?= Date: Sat, 18 Aug 2018 11:41:01 +0200 Subject: [PATCH] Added a try-catch in order to avoid TypeError: only integer scalar arrays can be converted to a scalar index exception in readFlowFile.py --- readFlowFile.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/readFlowFile.py b/readFlowFile.py index 7efaa08..4d0c7ba 100644 --- a/readFlowFile.py +++ b/readFlowFile.py @@ -26,7 +26,11 @@ def read(file): w = np.fromfile(f, np.int32, count=1) h = np.fromfile(f, np.int32, count=1) #if error try: data = np.fromfile(f, np.float32, count=2*w[0]*h[0]) - data = np.fromfile(f, np.float32, count=2*w*h) + try: #try first option + data = np.fromfile(f, np.float32, count=2*w*h) + except: + # if TypeError: only integer scalar arrays can be converted to a scalar index raise + data = np.fromfile(f, np.float32, count=2*w[0]*h[0]) # Reshape data into 3D array (columns, rows, bands) flow = np.resize(data, (int(h), int(w), 2)) f.close()