Skip to content

Instantly share code, notes, and snippets.

@lifangda01
Created June 4, 2019 20:51
Show Gist options
  • Save lifangda01/93ac8d77f5209b9fcd92cada7c5a35c4 to your computer and use it in GitHub Desktop.
Save lifangda01/93ac8d77f5209b9fcd92cada7c5a35c4 to your computer and use it in GitHub Desktop.
Convert 3D numpy array to vti format
import numpy as np
import pyevtk
np_data = np.load('/Users/fangdali/Code/DEBATR/results/wFBP/freect/bag_no_5'
'/whole_bag.npz')['arr_0']
print np_data.shape
w, h, l = np_data.shape
x = np.arange(0, w + 1)
y = np.arange(0, h + 1)
z = np.arange(0, l + 1)
pyevtk.hl.imageToVTK('/Users/fangdali/Code/DEBATR/results/wFBP/freect/bag_no_5'
'/whole_bag', cellData={'data': np_data})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment