Skip to content

Instantly share code, notes, and snippets.

@JPFrancoia
Last active June 24, 2018 10:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JPFrancoia/37246e016e4fba56363423497a8b75b7 to your computer and use it in GitHub Desktop.
Save JPFrancoia/37246e016e4fba56363423497a8b75b7 to your computer and use it in GitHub Desktop.
Equivalent to Matlab fread function
def fread(fid, nelements, dtype):
"""Equivalent to Matlab fread function"""
if dtype is np.str:
dt = np.uint8 # WARNING: assuming 8-bit ASCII for np.str!
else:
dt = dtype
data_array = np.fromfile(fid, dt, nelements)
data_array.shape = (nelements, 1)
return data_array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment