本文介紹了使用 NumPy 數(shù)組數(shù)據(jù)編寫原始二進制文件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我想將 numpy 浮點數(shù)組的內(nèi)容作為有符號 16 位整數(shù)保存到原始二進制文件中.我嘗試使用 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.
推薦答案
我認為最簡單的方法是先將數(shù)組轉(zhuǎn)換為int16,
I think the easiest way to do this is to first convert the array to int16,
array.astype('int16').tofile(filename)
這篇關(guān)于使用 NumPy 數(shù)組數(shù)據(jù)編寫原始二進制文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!