binaryfiles

store/load numpy array from binary files

岁酱吖の 提交于 2021-01-28 04:58:06
问题 I would like to store and load numpy arrays from binary files. For that purposes, I created two small functions. Each binary file should contain the dimensionality of the given matrix. def saveArrayToFile(data, fileName): with open(fileName, 'w') as file: a = array.array('f') nSamples, ndim = data.shape a.extend([nSamples, ndim]) # write number of elements and dimensions a.fromstring(data.tostring()) a.tofile(file) def readArrayFromFile(fileName): _featDesc = np.fromfile(fileName, 'f') _ndesc

Why doesn't the istreambuf_iterator advance work

本小妞迷上赌 提交于 2021-01-27 18:40:11
问题 I was reading Constructing a vector with istream_iterators which is about reading a complete file contents into a vector of chars. While I want a portion of a file to be loaded in to a vector of chars. #include <iostream> #include <fstream> #include <iterator> #include <vector> #include <algorithm> using namespace std; int main(int argc, char *argv[]) { ifstream ifs(argv[1], ios::binary); istreambuf_iterator<char> beginItr(ifs); istreambuf_iterator<char> endItr(beginItr); advance(endItr, 4);

Random numbers external sort

眉间皱痕 提交于 2021-01-01 06:47:45
问题 I need to write a program that generates N random numbers and write them to binary file in descending order. It should be done without using any of sorting algorithms that use main memory. This is what I've done so far: #include <iostream> #include <fstream> #include <ctime> #include <cstdlib> using namespace std; int main () { srand(time(0)); rand(); int N; do{ cout << "Unesite N: "; cin >> N; } while(N<=0); ofstream br("broj.dat", ios::binary | ios::trunc); for(int i = 0; i<N; i++){ int a =

C++ reading a file in binary mode. Problems with END OF FILE

雨燕双飞 提交于 2020-12-30 03:15:18
问题 I am learning C++and I have to read a file in binary mode. Here's how I do it (following the C++ reference): unsigned values[255]; unsigned total; ifstream in ("test.txt", ifstream::binary); while(in.good()){ unsigned val = in.get(); if(in.good()){ values[val]++; total++; cout << val <<endl; } } in.close(); So, I am reading the file byte per byte till in.good() is true. I put some cout at the end of the while in order to understand what's happening, and here is the output: marco@iceland:~

Is it possible to edit a binary file using Windows command line?

筅森魡賤 提交于 2020-12-29 06:39:37
问题 Is there a way in Windows to edit a binary file, from the command line? i.e. a way that could be written into a batch file? I want to be able to edit a single byte, at a known position, in an existing file. This existing question[1] is solved, but that's a Linux solution. I'm looking for something similar for Windows. Background There's a bug in GTA 1 when downloaded from Steam whereby the save-game data file gets corrupted on exit. As a result, the game can be played fine the first time but

Write binary data to file, literally

Deadly 提交于 2020-08-22 16:42:06
问题 I have an array of integers Array ( [0] => Array ( [0] => 1531412763 [1] => 1439959339 [2] => 76 [3] => 122 [4] => 200 [5] => 4550 [6] => 444 ) ... And so on, I suppose if I look at it as if it were a database - the elements of the outermost array are the rows and the elements of the inner arrays are the columns. I want to save that information into a file, so that I will be able to retrieve it later but I want to save it as binary data to save space. Basically if I write the first integer

How to tell git to preserve CRLF specifically for a single set of files? Mark a text file as binary?

送分小仙女□ 提交于 2020-08-10 19:45:13
问题 I want to set some of the text files in a repo to be cloned/downloaded as binary. Ie: Bypass the CRLF settings in git and just clone byte per byte. Context There are myriads of posts about CRLF in git. But normally they are about the general settings of whole projects, mainly depending on if you use Linux or Windows. But I face a situation that never found before. I am willing to set a folder in my project with sample emails as defined by the RFC 5322 which define that the end-of-line of the

How to tell git to preserve CRLF specifically for a single set of files? Mark a text file as binary?

こ雲淡風輕ζ 提交于 2020-08-10 19:45:12
问题 I want to set some of the text files in a repo to be cloned/downloaded as binary. Ie: Bypass the CRLF settings in git and just clone byte per byte. Context There are myriads of posts about CRLF in git. But normally they are about the general settings of whole projects, mainly depending on if you use Linux or Windows. But I face a situation that never found before. I am willing to set a folder in my project with sample emails as defined by the RFC 5322 which define that the end-of-line of the

Writing binary file using in Extendscript. Incorrect file size

一个人想着一个人 提交于 2020-08-05 10:06:06
问题 Further to my question here I'm writing a list of hex colours to a binary file from within Photoshop using Extendscript. So far so good. Only the binary file written with the code below is 119 bytes. When cut and pasted and saved using Sublime Text 3 it's only 48 bytes, which then causes complications later on. This is my first time in binary land, so I may be a little lost. I suspect it's an either an encoding issue (which could explain the 2.5 file size), or doing something very wrong