English 中文(简体)
Reading hex string file in Julia
原标题:

In python, I do

import numpy as np
data = np.memmap( mydata.bin , dtype= <i4 , mode= r )

How can I implement this in Julia? I was reading about readbytes and htol but couldn t figure out.

问题回答

The key is using the MMap library and the function mmap():

using Random, Mmap

# first, create a binary file for us to use, to test that our program works:

# 1000 random numbers between 1 and 100000
mydata::Vector{Int32} = rand(1:100000, 1000) 

# write it as a binary file
open("mydata.bin", "w") do io
    write(io, mydata)
end

Then call mmap():

# read the binary file
mydata2 = mmap("mydata.bin", Vector{Int32})

More information can be found in the documentation here or the source code here.

Another alternative is UnixMmap, which uses Unix s mmap interface (so it would only work for Unix-like operating systems, such as Linux or MacOS (i.e. no Windows support)

Credit to Gnimuc, Reza Afzalan, and Aung!





相关问题
Printing several binary data fields from Google DataStore?

I m using Google App Engine and python for a web service. Some of the models (tables) I have in my web service have several binary data fields in them, and I d like to present this data to a computer ...

Handling large ActiveRecord object set as binary data

I have an issue with manipulating large number of record objects of type ActiveRecord model(Records are extracted from a complex operation but from the same table) and I want to pass that object set ...

How to send a push notification using Erlang?

I m trying to send a push notification to APNs using Erlang. This is the code I came up with so far: -module(apnstest2). -export([connect/0]). connect() -> application:start(ssl), ssl:...

What is a suitable buffer for Python s struct module

In Python I m accessing a binary file by reading it into a string and then using struct.unpack(...). Now I want to write to that string using struct.pack_into(...), but I get the error "Cannot use ...

Storing hexadecimal values as binary in MySQL

I was thinking about how I m storing passwords in my database : appropriately salted SHA1 strings in a CHAR(40) field. However, since the character data in there is actually just a hex representation ...

View ram in DOS

Is there a way in dos (im using a dos boot disk on a linux machine) to view portions of ram? ie. some form of command to read the binary at a given address? edit: my bootable floppy doesnt have ...

热门标签