本文介紹了使用 NumPy 數組數據編寫原始二進制文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想將 numpy 浮點數組的內容作為有符號 16 位整數保存到原始二進制文件中.我嘗試使用 ndarray.tofile 來完成此操作但我無法找出正確的格式字符串.似乎文件以雙重格式保存,無論我如何選擇格式字符串.我該怎么做呢?謝謝.
I'd like to save the contents of a numpy float array into a raw binary file as signed 16 bit integers. I tried to accomplish this using ndarray.tofile but I can't figure out the right format string. It seems that the file is saved in double format, mo matter how I choose the format string. How do I do this? Thanks.
推薦答案
我認為最簡單的方法是先將數組轉換為int16,
I think the easiest way to do this is to first convert the array to int16,
array.astype('int16').tofile(filename)
這篇關于使用 NumPy 數組數據編寫原始二進制文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!