본문 바로가기
SW programming/Python

[Python] .npy to .mem 파일 변환

by 고뭉나무 2023. 9. 18.

Python코드로 .npy to .mem 파일 변환하는 방법

 

import numpy as np
from fxpmath import Fxp

layer_name = 'ending.resq'

# load .npy file
inp1 = np.load(f'./rtl_test/{layer_name}_inp0.npy')

# Total data length: 16bit, fraction bit: 0bit, signed
inp1_fxp = Fxp(inp1, n_word=16, n_frac=0, signed=True) 

# save to .mem file
with open(f'memfile/{layer_name}_inp0_split0.mem', 'w') as f:
  for v in inp1_fxp.flatten().bin():    # convert to binary bit
    f.write(v+'\n')

 

 

참고

 fxpmath library

https://github.com/francof2a/fxpmath

 

GitHub - francof2a/fxpmath: A python library for fractional fixed-point (base 2) arithmetic and binary manipulation with Numpy c

A python library for fractional fixed-point (base 2) arithmetic and binary manipulation with Numpy compatibility. - GitHub - francof2a/fxpmath: A python library for fractional fixed-point (base 2) ...

github.com

 

 
반응형

댓글